Menu
Question Index
...

What will be the output of the following program?

public class GetStarted {
    public static void main(String... args) {
        Hai obj1 = new Hi();
        Hello obj2 = (Hello) obj1;
        System.out.print(obj1.method1());
        if (true) {
            System.out.print(" ");
        } else {
            System.out.println();
        }
        System.out.print(obj2.bye);
    }
}
class Hai {
    int seeYou = 99;
    int method1() {    return seeYou;    }
}
class Hello extends Hai {
    int bye = 199;
    int method1() {    return bye;    }
}
class Hi extends Hello {
    int byee = 299;
    int method1() {    return byee;    }
}


299 199
199 199
299 99
199 99
Compilation Error
Runtime Error

Doubts

Problems

Topic: Multilevel Inheritance In Java With Example Program

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App