SCJP Module-1 Question-8


 

SCJP Module-1 Question-8

The given program heps and tests the in understating of abstract classes in core Java and it is very useful for SCJP exam preparation.

The given program heps and tests the in understating of abstract classes in core Java and it is very useful for SCJP exam preparation.

Given a sample code:

1 class Ball {
2 abstract void sayHello();
}

3 class Football extends Ball {
4 void sayHello() {
5 System.out.println("hello");
6 }}

7 public class Sample2 {
8 public static void main(String args[]) {
9 Football f = new Football();
10 f.sayHello();
11 }}

What is the correct statement for the line number 1 ?

(1) Compilation succeeds no issue
(2) abstract
(3) interface
(4) public

Answer

(2)

Explanations:

 The abstract keyword must be place before the class Ball because abstract method can only exist in the abstract class not in concrete class.

Ads