Menu
Topics Index
...
`

Creating classes and method Overriding


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating classes and method Overriding
What will be the output of the following program?
public class Started {
    public static void main(String args[]) {
        Computer mouse = new Laptop();
        System.out.println(mouse.getValue(100, 200));
    }
}
class NoteBook {
    int getValue(int a, int b) {
        if (a > b)
            return a;
        else
            return b;
    }
}
class Computer extends NoteBook {
    int getValue(int a, int b) {
        return 2 * super.getValue(b, b);
    }
}
class Laptop extends Computer {
    int getValue(int a, int b) {
        return super.getValue(2 - b, 2 * b);
    }
}

A. 200
B. 400
C. 798
D. 800
E. Compilation Error or Runtime Error
Topic: Super Keyword In Java To Call Super Class Constructor

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is D..

Posted by Om Prakash Om    2013-09-06 09:21:27


D is the answer..bcz mouse is the object of computer which is equal to laptop..and laptop has all the access since its extending computer which inturn is extends notebook.

Posted by Shabaaz Shaikz    2013-09-06 09:27:15


Ans is D...as getValue() of laptop class is executed due to function overriding...which inturn class getValue() of Computer and getValue() in computer calls getValue() of NoteBook class.

Posted by Krishna Sai    2013-09-06 09:27:44


Congratulations Krishna Sai Mulpuri. You are this dose winner. We will send the link using which you can claim your recharge.

Posted by Merit Campus    2013-09-08 12:08:04


© meritcampus 2019

All Rights Reserved.

Open In App