This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract class qustion from khalid book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Abstract class qustion from khalid book" Watch "Abstract class qustion from khalid book" New topic
Author

Abstract class qustion from khalid book

Tosin Adedoyin
Ranch Hand

Joined: Nov 09, 2001
Posts: 43
Which one of the following class defination of a class that cannot be instantiated
Select the one right answer
a) class Ghost{
absract void haunt ();
}
b) abstract class Ghost{
void haunt ();
}
c) abstract class Ghost{
absract void haunt (){};
}
d)
abstract Ghost{
absract void haunt ();
}
e) static class Ghost
{
abstract haunt ();
}
the ans is c i feel if c is correct b is also correct because the method is not implemented we dont need a brace because that is the difference between c and b
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
method in b is not declared as abstract so it does need brace!


Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
are you sure c is correct?
I think putting brace there will cause a compil error!
Vanitha Sugumaran
Ranch Hand

Joined: Apr 11, 2001
Posts: 356
Hi,
In my book, the answer choices are like this..
Which is legal definition of a class that can't be instantiated?
a)class Ghost{
abstract void haunt();
}
// compiler error since class isn't declared abstract
b) abstract class Ghost{
void haunt();
}
// the method haunt is not implemented (no braces)

c) abstract class Ghost {
void haunt(){};
}

// this is legal definition of the abstract class
so the answer choice c is correct
d)abstract Ghost{
abstarct void haunt();
}
// missing class

hope this helps,
Vanitha.
Tosin Adedoyin
Ranch Hand

Joined: Nov 09, 2001
Posts: 43
i feel that the braces should not make the difference with answer b absract methods in abstract classes do not have to be implemeted anywway so the brace should not make a diference should it ???
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
if a method is not declared abstract in an abstarct class then it should have a body (implentaion) ie the braces.
thats y b is wrong.
if u dont want to provide an implentaion then declare it abstract and use the ; at the end.
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
Originally posted by Vanitha Sugumaran:
Hi,
In my book, the answer choices are like this..
Which is legal definition of a class that can't be instantiated?
a)class Ghost{
abstract void haunt();
}
// compiler error since class isn't declared abstract
b) abstract class Ghost{
void haunt();
}
// the method haunt is not implemented (no braces)

c) abstract class Ghost {
void haunt(){};
}

// this is legal definition of the abstract class
so the answer choice c is correct
d)abstract Ghost{
abstarct void haunt();
}
// missing class

hope this helps,
Vanitha.

I do totally agree with you but the C coming from Tosin is not exactly the same,
abstract class Ghost{
absract void haunt (){};
}

The method is also declared abstract with braces! And he says that's the good answer. I feel that there is no good answers in his case. Maybe he didn't pay attention when copying? Do you have the same book?
Tosin Adedoyin
Ranch Hand

Joined: Nov 09, 2001
Posts: 43
sorry c should have been
absract class Ghost
{
void haunt (){};
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Abstract class qustion from khalid book
 
Similar Threads
abstract class
abstract Classes
Abstract Class
Abstract Classes
abstract