Share on Google+Share on Google+

SCJP Module-1 Question-11

Advertisement
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.

Advertisements

Posted on: July 7, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.