How to declare java abstract class?

http://www.quizover.com/java-certification-questions

Title: Oracle Certified Professional Java Programmer

Permalink:

Author: JavaChamp Team Senior Java Developer Germany

Responses: 57303

Created: 3 years

Access: Registered Instant Grading

Share Quiz:

Start Quiz Email Share </> Embed
Copy and paste the following HTML code into your website or blog.
<iframe src="http://www.quizover.com/embed/java-certification-questions" 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:
http://www.quizover.com/java-certification-questions
Question Permalink:
http://www.quizover.com/how-to-declare-java-abstract-class
Which of the following declaration will compile without errors?
Choose 2



Explanation:

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

An abstract method has no implementation .

Total comments (14)

2014-04-22T17:43CEST
if an abstract class contains concrete methods it still compiles fine
2014-04-22T17:43CEST
Even if an abstract class has all concrete methods we can still mark it abstract.. it will compile fine
Brijesh Soni Java Developer 4site Technology Gujarat  5 months
2013-11-06T02:06CET
option 5 is correct
Nitendra Dhaked  8 months
2013-08-10T08:53CEST
non abstract mehod must have body in abstract class.
2012-08-11T16:09CEST
- 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!
2012-08-11T16:09CEST
- 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
2012-06-16T06:17CEST
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
2011-10-24T21:05CEST
@horvath.agoston

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

Horvath.agoston  3 years
2011-01-26T11:08CET
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
2010-05-13T08:48CEST
The wording was amended, thanks spencetj
Anonymous User  3 years
2010-05-12T17:14CEST
The question wording doesn't make sense. Is it asking for compilation errors or error-free compilations?
Naj M Java Developer USA  4 years
2010-03-11T08:18CET
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
2010-03-11T08:17CET
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.

2010-03-10T20:01CET
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.
Inline