Here's a simple one from Mughal. Which of these two is a legal definition of a class that cannot be instantiated? //1 abstract class Ghost { void haunt(); } OR //2 abstract class Ghost { void haunt(){}; }
The answer given is 2. Why? Thanks Rahul
Paul Anilprem
Enthuware Software Support
Ranch Hand
Joined: Sep 23, 2000
Posts: 2912
posted
0
void haunt(); : If you do not provide a body then you must declare it abstract. ------------------ Get Certified, Guaranteed! (Now Revised for the new Pattern) www.enthuware.com/jqplus
In your second case u have decalred an abstract class comtaining a non abstract method.That is perfectly fine.
sona gold
Ranch Hand
Joined: Feb 14, 2001
Posts: 234
posted
0
but the question here is which is the right declaration for a class that cannot be instantiated. both the above shown classes are abstract and hence cannot be instantiated.
sona<br />SCJP
rajashree ghatak
Ranch Hand
Joined: Mar 10, 2001
Posts: 151
posted
0
no the first one is illegal declaration of an abstract class.The reason being "If you do not provide a body to a method then you must declare it abstract". Notice void haunt(); which doesnot have abstract keyword in its declaration. Therefore only 2nd class declaration is valid. rajashree.
sona gold
Ranch Hand
Joined: Feb 14, 2001
Posts: 234
posted
0
thanks rajashree u got a point here i missed it yes so the 2nd option is the right answer
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.