Menu
Question Index
...

What is the output of the following program?

public class BackWithVengeance {
    public static void main(String[] args) {
        new Yuvi().bat();
        new Yuvaraj().bat();
        ((Yuvi) new Yuvaraj()).bat();
    }
}
class Yuvi {
    void bat() { System.out.print("Unbeatean "); }
}
class Yuvaraj extends Yuvi {
    void bat(int i) { System.out.print(i + " "); }
    void bat() {
        System.out.print("Yuvraj's ");
        super.bat();
        this.bat(77);
    }
}


Unbeatean Yuvraj's Unbeatean 77 Unbeatean
Unbeatean Yuvraj's Unbeatean 77 Yuvraj's Unbeatean 77
Compilation error because super should be the first statement in the method
Compilation error for some other reason or Runtime Error

Doubts

Problems

Topic: Assigning Super Class Reference To A Sub Class Reference In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App