Is this a valid abstract class because the method has ';'
abstract class Automobile{
void honk(){}; //(3)
}
Please advise!
About Question enthuware.ocajp.i.v7.2.1178 :
Moderator: admin
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1178 :
Yes, it is valid. Extra semicolon is not needed but is not an error either.
-Paul.
-Paul.
-
- Posts: 6
- Joined: Mon Jun 29, 2015 8:41 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1178 :
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.
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.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1178 :
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.
HTH,
Paul.
Who is online
Users browsing this forum: No registered users and 5 guests