This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi everybody, i have some simple,basic questions...hope someone can clear my doubts... 1. does a class having final method be declared final? 2. can overloaded methods throw exception that is not in the other method? what are the exception rules for method overloading? 3. are long and float variables valid if declared as long l=256788; float f=8.909923; ie. without L/l and f following them....? 4. i saw this question s += i; where s is short and i is integer and finally when you evaluate it is stored in short then howcome this expression is valid? are the rules diffrent for short circuit evaluation? 5. which of the following are valid gridbag constraints? 1 ipadx 2 fill 3 insets 4 width the right answer is 1,2. why is insets not a valid constraint? i guess it is also a constraint in gridbad constraint class thank you gayathri
Here's some answers from the studying I've been doing... 1. A class with a final method does not need to be final. However, that method can't be overriden in a subclass. 2. Overloaded methods can throw any exceptions they want - there really isn't any relationship other than the name. 3. long l=256788; This declaration is o.k. float f=8.909923; This will throw a compile error - a literal value with a decimal in it has a default value of a double - so you'd have to declare it as float f=8.909923f or cast it to a float;
[This message has been edited by Pam Doucette (edited March 21, 2001).] [This message has been edited by Pam Doucette (edited March 21, 2001).]
Hi Gayathri, 1. A class having final method need not be declared final. You can do so, but then the final modifier of the method will be anyway redundant. 2. Overloaded methods should be able to throw exceptions not thrown in the other method. 3. long variables are valid if declared without l. float without f will throw a compiler error. 4. Yes. The rules for short ckt evaluation are an exception to the rules of arithmetic promotion. ------------------ Hope this helps. Correct me if I am wrong. Cheers , Kapil [This message has been edited by kapil apshankar (edited March 21, 2001).]
Hope this helps. Correct me if I am wrong.<p>Cheers <img src="smile.gif" border="0"> ,<br />Kapil
hi rules for short circuit short s; int i; s+=i // is allowed , int is automatically converted to short no casting required here. but s= s+i // illegal , cause this expression will result in an int value , so it has to be expiliclty casted to short. s= (short) s+i;//now legal, as stated above s+=i does not require casting. hope this helps..
Joined: Jan 29, 2001
Thank you all so much. now iam clear....the question regarding the insets constaraint and the long, float declaration are from khalid and so be careful when you do the tests. thanks to u all again gayathri