1) Compile time error, an abstract class cannot have non abstract methods. 2) Compile time error, the equals method of the String class takes a String parameter not a StringBuffer 3) Compile time error, class Ilea does not implement the getLeader method of Lcc 4) Compilation and output of "equals" 5) Compilation, but no output at runtime
The answer is 5th option(Compilation, but no output at runtime). I compiled the same and found that the answer is correct.
Can anyone please explain this answer?
Thanks in advance Sajeena.
[ August 03, 2005: Message edited by: Sajeena Binoj ] [ August 03, 2005: Message edited by: Barry Gaunt ]
Rick O'Shay
Ranch Hand
Joined: Sep 19, 2004
Posts: 531
posted
0
Sure, there's nothing wrong with any of the code and so it compiles and runs and the comparison fails. A StringBuffer will never equal a String, no matter what the content of each is. That's part of the canonical equals() contract.
Sajeena Binoj
Greenhorn
Joined: Jul 29, 2005
Posts: 6
posted
0
Thanks Rick.
deshdeep divakar
Ranch Hand
Joined: Apr 19, 2004
Posts: 91
posted
0
Hello Rick,
do'nt you think the answer should be compilation error also coz public method getLeader() is not implemented in concrete class which is must. Thanks & Regards Java Man Deshdeep
"Do not be afraid of going slow, be afraid of standing still"
deshdeep divakar
Ranch Hand
Joined: Apr 19, 2004
Posts: 91
posted
0
Hello Rick,
do'nt you think the answer should be compilation error also coz public method getLeader() is not implemented in concrete class which is must. Thanks & Regards Java Man Deshdeep
Seenu Reddy
Ranch Hand
Joined: Apr 03, 2002
Posts: 108
posted
0
deshdeep,
the getLeader() method in class LCC is not abstract method. so its not must to override the same. if the method is declared abstact, then it must override the method in the sub class.