This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hey, Khalid Moughul's book says that " a final variable need not be initialized at it's declaration, but it must be initialized once before it is used. These variables are also known as blank final variables". Going according to the above quote, my following program should perfectly compile and also print "Done It" on the screen, since I am just declaraing the the final variables, but not using them anywhere. ************************************ class test155 { final int i; final static int b; public static void main(String args[]) { System.out.println("Done It"); } } Compiling the above code, gives the following error on my system: test155.java:3: Blank final variable 'i' may not have been initialized. It must be assigned a value in an initializer, or in every constructor. final int i; ^ test155.java:4: Blank final variable 'b' may not have been initialized. It must be assigned a value in an initializer, or in every constructor. final static int b; ^
************************************* Also, Can somebody clearly pin point the differnce between an interface and an abstract class having abstract methods? Bye, Tualha Khan
You need to initialize it either in main or in a constructir before using it. The intialization rferred to in Khalids book refrets to this but ur code doesn't have any intilazation.
hi Refer to www.absolutejava's titbits in one of the titbits it is mentioned very clearly i don rember which 1 AMIT
<I>Chance Favours the Prepared minds"</I>
Tualha Khan
Ranch Hand
Joined: Nov 22, 2000
Posts: 287
posted
0
Dear Hemal, I know that i should initialize the final variables before using them. This can be done either in main() or in the constructor or otherwise. But my point is that, if I am not using them in my program then I don't need to (or want to) initialize them. Khalid's book says, that I need not initialize them while declaring them, but I should initialize them BEFORE I start to USE them. Now in my program, I am just initialing them, but not using them. So it should not give me any problem. Please clarify this point to me, maybe I am wrong or confused, I need a little helping hand here. Thanks. Bye, Tualha Khan
Tualha Khan
Ranch Hand
Joined: Nov 22, 2000
Posts: 287
posted
0
sorry, I mean I am just declaring them and not initializing them. See in the second or third paragraph of the message. Bye, Tualha Khan
i) Interfaces are the means of multiple inheritance in java where as you cannot extend more than one abstract (or concrete) class. You can implement more than one interface. ii) Interfaces cannot contain implementation of the methods whereas abstract class can contain concrete methods. iii) In interfaces variables are public,static and final implicitly. HTH
Hi Tualha Khan, Java compailer gives proper error messages when final variable needs to be initialized. It says "Blank final variable 'i' may not have been initialized. It must be assigned a value in an initializer, or in every constructor." If you have two constructors and if you are initializing in one constructor, you still get the error message. Pl note "It must be assigned a value in an initializer, or in every constructor". Hope this is clear for you. Santhosh Kumar.
Tualha Khan
Ranch Hand
Joined: Nov 22, 2000
Posts: 287
posted
0
thanks santosh, got the point!! Thanks once again!! Bye, Tualha Khan
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.