How to declare java abstract class?

Title: Oracle Certified Professional Java Programmer


Author: JavaChamp Team Senior Java Developer Germany

Responses: 57265

Created: 3 years

Access: Registered

Share Quiz:

Start Quiz Email Share </> Embed
Copy and paste the following HTML code into your website or blog.
<iframe src="" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>
Author: JavaChamp Team  
Quiz Permalink:
Question Permalink:
Which of the following declaration will compile without errors?
Choose 2


if a class contains an abstract method , then it must be marked abstract.

An abstract method has no implementation .

Total comments (12)

Brijesh Soni Java Developer 4site Technology Gujarat  5 months
option 5 is correct
Nitendra Dhaked  8 months
non abstract mehod must have body in abstract class.
- a method without a body MUST be marked as abstract => then also its class MUST be marked as abstract else compilation error. Else the method must be given a body!
- an abstract METHODis a method with no body(so it must end with a semicolon(;) to mark its end) + it must be declared as "abstract" + its class must also be declared "abstract"

- an abstract CLASS is a class declared "abstract" and it can contain or not: abstract AND/or concrete(with a body) methods

- a class that has AT LEAST 1 abstract method MUST be declared abstract

Amrish Jhaveri Student India  1 year
only 1 is correct!!! no. 4 is incorrect since it has no body and no. 5 is incorrect since it has a semicolon which is incorrect.
Anonymous User  2 years

Yeah, and public void print(); has no body. 4th is invalid.

Horvath.agoston  3 years
The question is incorrect, answer 4 is valid. A class marked as abstract doesn't actually have to have any abstract members. However, if a class has any abstract members, it HAS TO BE marked as abstract. These 2 statements are not the same.
JavaChamp Team Senior Java Developer Germany  3 years
The wording was amended, thanks spencetj
Anonymous User  3 years
The question wording doesn't make sense. Is it asking for compilation errors or error-free compilations?
Naj M Java Developer USA  4 years
The braces in a method with implementation, them alone indicate the start and end of a method to a compiler, with no need to a semi colon. But it's presence doesn't cause any compilation error, because the compiler sees the end of the method by the last brace , then see emptiness (no statement) then semi colon.

In an abstract method, you must state for the compiler the end of the method declaration by a semi colon , since no braces are there.

Naj M Java Developer USA  4 years
As you said, it is unneeded, but it's presence doesn't cause any compilation error. Actually you can add 10 semi colons after the method and still no errors produced.

A semi colon in Java indicates the end of a statement.

I don't believe number five is correct, though I could be wrong. Wouldn't there be a compilation error on number 5 due to the unneeded semicolon?
Content license and Copyright  Oracle, Sun, Java and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates.