About Question enthuware.ocajp.i.v7.2.1178 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Deepa

About Question enthuware.ocajp.i.v7.2.1178 :

Post by Deepa »

Is this a valid abstract class because the method has ';'
abstract class Automobile{
void honk(){}; //(3)
}
Please advise!

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1178 :

Post by admin »

Yes, it is valid. Extra semicolon is not needed but is not an error either.
-Paul.

jayallenloew
Posts: 6
Joined: Mon Jun 29, 2015 8:41 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1178 :

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1178 :

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests