Menu
Topics Index
...
`

Method overriding and calling super class method


If you need explanation Read this topic

If you need Answer Take test on this topic

Method overriding and calling super class method
What will be the output of the following program?
class Fruit {
    public void eat() throws Exception {
        System.out.println("Eating fruit");
    }
}
public class Apple extends Fruit {
    public void eat() {
        System.out.println("Eating apple");
    }
    public static void main(String[] args) throws Exception {
        Fruit f = new Apple();
        f.eat();
    }
}

A. Eating apple
B. Eating fruit
Eating apple
C. Eating apple
Eating fruit
D. Eating fruit
E. Some other output
F. Compilation Error or Runtime Error
Topic: Exception Handling Syntax In Java Programming

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 A..bcz of function-overriding..always submost class functionality will gets executed

Posted by Krishna Sai    2013-09-23 08:50:07


A is answer as eat() is overridden.and besides,we are creating class of Apple using Fruit f as reference object, so eat() of class Apple gets printed.

Posted by Shabaaz Shaikz    2013-09-23 10:56:12


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

Posted by Merit Campus    2013-09-24 06:59:12


© meritcampus 2019

All Rights Reserved.

Open In App