SCJP Module-1 Question-11


 

SCJP Module-1 Question-11

This program helps in understanding of inheritance in core Java and helpful for SCJP examination

This program helps in understanding of inheritance in core Java and helpful for SCJP examination

Given a sample code:

1 class Test {
2 void printTest() {
3 System.out.println("superclass");
}}

4 class Sample1 extends Test {
5 Sample1() {
6 super.printTest();
}

7 public static void main(String args[]) {
8 new Sample1();
}}

What will be the result of above code ?

(1) Compilation fails because of an error on line 6
(2) Compilation fails because of an error on line 8
(3) Compilation fails because of an error on line 3
(4) Compile and run successfully with no error

Answer

(4)

Explanation:

It has no issue with the code. It will display the output on console.

Ads