This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes public static final Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "public static final " Watch "public static final " New topic

public static final

Jammy Wells

Joined: Oct 04, 2007
Posts: 17
I have started reading Kathy Sierra Scjp 1.4 book....In the second chapter we have a question which asks indirectly whether U can compile "public static final int k;" as an instance variable declaration or not and the answer provided for this was that U can. I tried writing a class which declares a member variable in above mentioned manner,it gave me a compilation error according to which I shud have initialized this variable by assiging sme value to it.Please tell me whether its smething wrong in the Book's mentioned statement or smething else.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193


Welcome to JavaRanch!

"public static final int i;" is legal, but only if you initialize the variable somewhere, such as in a static initialization block. For example,

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: public static final
It's not a secret anymore!