Menu
Topics Index
...
`

MultilevelInheritance


If you need explanation Read this topic

If you need Answer Take test on this topic

MultilevelInheritance
What will be the output of following program?
class Scooter {

    public Scooter() {
    }
}

class Honda extends Scooter {

    public Honda() {
    }

    public void mileage() {
        System.out.println("Min: 30Km");
    }

    public void speed() {
        System.out.println("Max: 90Kmph");
    }
}

public class HondaShine extends Honda {

    public HondaShine() {
        System.out.println("Honda Model: Shine");
    }

    @Override
    public void speed() {
        System.out.println("Max: 80Kmph");
    }

    public static void main(String args[]) {
        HondaShine obj = new HondaShine();
        obj.mileage();
        obj.speed();
    }
}

A. Honda Model: Shine
Min: 30Km
Max: 90Kmph
B. Honda Model: Shine
Min: 30Km
Max: 80Kmph
C. Some other output
D. Compilation Error or Runtime Error
Topic: Multilevel Inheritance In Java With Example Program

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.

B

Posted by Ankur Verma    2014-11-24 12:44:41


Ans is B..here we have the concept of inheritance which means a class deriving the properties of the another class...this can perform using the extends keyword...

here we have the multilevel inheritance means deriving the Child class from the another child class means Ex: A is Parent and B is Child of  A and B is the Parent of C..A->B->C..this is multilevel inheritance...

here Scooter is the Parent class and Honda is Child class and HondaShine is Child of the Honda...

here we create the Instance for the HondaShine class  so that Construcot of HondaShine will executed and than we are calling Milege() than it wil call the method in Honda class bcz HondaShine is Child of the class than we are calling speed() it wil execute the method in HindaShine() bcz here it is presented in this class only and @Override means it is an annotation which wii tels the compiler to this method is overided from its Parent class

Posted by Uday Kumar    2014-11-24 12:52:01


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Ramya Reddy Addulla. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-11-25 02:48:28


© meritcampus 2019

All Rights Reserved.

Open In App