Menu
Topics Index
...
`

Revolution 2020


If you need explanation Read this topic

If you need Answer Take test on this topic

Revolution 2020
What will be the output of the following program?
public class Revolution2020 {
    public static void main(String[] args) {
        Love love = new Love();
        love.aarti();
        Ambition gopal = new Corruption();
        Ambition raghav = new Ambition() {
            public String goal() {
                return "Pen Is Powerful ";
            }
            public void aarti() {
                System.out.print("Respect ");
            }
        };
        gopal.aarti(); gopal.goal();
        raghav.aarti(); raghav.goal();
        System.out.print(((Corruption) gopal).shukla());
    }
}
class Love {
    void aarti() { System.out.print("Beautiful ");    }
}
interface Ambition {
    String goal();
    void aarti();
}
class Corruption extends Love implements Ambition {
    int shukla() throws Exception { return 2020; }
    public String goal() { return "Get Rich "; }
    public void aarti() { System.out.print("Confused "); }
}

A. Beautiful Confused Get Rich Respect 2020
B. Beautiful Confused Get Rich Respect Pen Is Powerful 2020
C. Beautiful Confused Respect 2020
D. Some other output
.E. Compilation Error or Runtime Error
Topic: Future Task Java Program Using Interfaces

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 E. Compilation error occurs since the method shukla() must catch the exception thrown.

Posted by Nikhil Sulibhavi    2014-05-13 13:16:19


There is a possibility of shukla() method (of Corruption class) throwing an Exception here (checked exceptions must either be caught or declared using throws key word). So shukla() method call inside main must be surrounded by a try-catch block or main() must declare the Exception using throws key word, which is not the case here. Therefore, compiler throws an error. So, the answer is E.

Posted by Shaileshwar Sharma    2014-05-13 13:18:29


Congratulations Nikhil Sulibhavi. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-05-14 04:02:41


Merit Campus Sir I didn't receive link for this dose. I request you to kindly look into it.

Posted by Nikhil Sulibhavi    2014-05-14 13:27:02


Hello Nikhil, We are sending it once more please check.

Posted by Merit Campus    2014-05-14 13:52:56


I received it now sir. Thank you

Posted by Nikhil Sulibhavi    2014-05-14 13:54:48


© meritcampus 2019

All Rights Reserved.

Open In App