aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "abstract class" Watch "abstract class" New topic
Author

abstract class

Rahul Ramachandran
Ranch Hand

Joined: Feb 27, 2001
Posts: 48
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: 3313
    
    7
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

Your guide to SCJD exam!
www.enthuware.com/jdevplus
Try out the world's only WebCompiler!
www.jdiscuss.com


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
nitin sharma
Ranch Hand

Joined: Feb 24, 2001
Posts: 290
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
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
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
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://aspose.com/file-tools
 
subject: abstract class