This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Which of the following represent valid code if it is the entire contents of a file called whitney.java?
1 abstract final class whitney{} 2 public final class whitney extends Object{} 3 public abstract class whitney{} 4 protected class whitney{}
The Correct Answer
2) public final class whitney extends Object{} 3) public abstract class whitney{}
I think answer 2 is wrong. If i'm worng pls explain.
Thank you in advance jaya [ November 08, 2004: Message edited by: jaya merugu ]
Toms Liepins
Greenhorn
Joined: Nov 02, 2004
Posts: 21
posted
0
Hi jaya, i believe that you have not understood the 'final' modifier. Final class/method can not be extended/overriden, however it DOES NOT mean that the final class ITSELF could not extend another nonfinal class. Answer 2 is correct (if you don't believe, try compiling
Krishna Srinivasan
Ranch Hand
Joined: Jul 28, 2003
Posts: 1803
posted
0
Answer 2,3 are correct. why answer 2 is wrong. canu you tell the reason? answer 2 syntax is perfectly valid.
Every class extends Object class implicitly. But explicitly mentioning it does not result in an error. An analogy to instance variables will make it clear.
String a;//a will be assigned null by default. String b=null;//is legal and null is assigned to b. similarly class A{} //A will extend Object by default class B extends Object {} //legal and B extends Object class.
Marcus Green
arch rival
Rancher
Joined: Sep 14, 1999
Posts: 2813
posted
0
It may seem a somewhat obscure point to test if you know that everything inherits from Object, even if it is not explicitly stated. However the great ancestor Object class provides some functionality that is used in threading, so it does have a practical application.