Home Tutorial Java Scjp Part1 SCJP Module-1 Question-30

 
 

SCJP Module-1 Question-30
Posted on: July 21, 2010 at 12:00 AM
The example given below will test your understanding about the Inheritance and method overriding in Java.

Given a sample code:

1    class One {
2    public One watch() {
3    System.out.println("One");
4    return this;
    }}

5    class Two extends One {
6    public One watch() {
7    System.out.println("Two");
8    return this;
    }}

9    class Test extends Two {

10  public One watch() {
11  System.out.println("Test");
12  return this;
    }

13  public static void main(String[] args) {
14  One t = new Test3();
15  t.watch();
    }}

What will be the result? Choose the correct option?

(A) One
(B) Two
(C) Test
(D) Compilation error at line no-14

Answer:

(C)

Related Tags for SCJP Module-1 Question-30:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.