Page 1 of 1
About Question enthuware.ocajp.i.v7.2.1178 :
Posted: Mon Dec 17, 2012 4:12 pm
by Deepa
Is this a valid abstract class because the method has ';'
abstract class Automobile{
void honk(){}; //(3)
}
Please advise!
Re: About Question enthuware.ocajp.i.v7.2.1178 :
Posted: Mon Dec 17, 2012 6:01 pm
by admin
Yes, it is valid. Extra semicolon is not needed but is not an error either.
-Paul.
Re: About Question enthuware.ocajp.i.v7.2.1178 :
Posted: Mon Dec 28, 2015 3:30 am
by jayallenloew
On this one, you need to re-word the question just slightly.
Change “…a class that cannot be instantiated” to
“…a class that cannot be instantiated directly”
or something to that effect.
The point is, abstract classes are not interfaces. They are indeed instantiated when a concrete subclass is instantiated.
So in this case, the following line of code would instantiate an Automobile, assuming correct inheritance:
Subaru Subbie = new Subaru(); // Subaru extends Automobile
The distinction is not trivial or irrelevant, and is treated in several Java textbooks. It is worth clarifying.
Re: About Question enthuware.ocajp.i.v7.2.1178 :
Posted: Mon Dec 28, 2015 8:32 am
by admin
While I agree with the point that you have made to some extent, the wording used by this question is as per the real exam.
HTH,
Paul.