SCJP Module-1 Question-24


 

SCJP Module-1 Question-24

The Sample program given below will test your understanding about the abstract class in Java.

The Sample program given below will test your understanding about the abstract class in Java.

Given a sample code:

1    abstract class Shape {
2    private int x, y;

3    public void setValue(int x, int y) {
4    this.x = x;
5    this.y = y;

6    System.out.println(x+y);
}}

7    class Test {
8    public static void main(String args) {
9    Shape s = new Shape();
10  s.setValue(1, 2);
}}

What will be the result? Choose the correct option?

(A) Successful run and print 3.
(B) Runtime error.
(C) Compilation error at line no 1.
(D) Compilation error at line no 9 that cannot create instance.

Answer:

(D)

Ads