Topics Index


If you need explanation Read this topic

If you need Answer Take test on this topic

What will be the output of the following program?
abstract class AbstractIt {
    abstract float isExecuted();
public class AbstractTest extends AbstractIt {
    protected float isExecuted() {
        try {
            try {
                System.out.println("No Compilation Error");
            } catch (Exception e) {
        } catch (Exception e) {
        return 1f;
    public static void main(String[] args) {
        AbstractTest at = new AbstractTest();

B. Error
C. No Compilation Error
D. Some other output
E. Compilation Error or Runtime Error
Topic: Try Catch Block In Java

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.

C. is the anwer as only the first SOP in try block is executed.

Posted by Shabaaz Shaikz    2013-12-31 08:45:05

Answer is C
1> abstract float isExecuted() in AbstractIt class is friendly (i.e. when no access modifier is specified) in derived class AbstractTest it is protected so no compilation error (anything protected or public is ok in derived class)
2> Netsted try catch is also no issue and there is no throw exception explicitly so no exception
3> return 1f is float value so no issue

Considering all above statement it should print "No Compilation Error" and return "1f" as no exception and no compilation error :)

Posted by Jayachandra Gupta    2013-12-31 08:46:46

Ans is E.. lf variable nt intialized but returning.. so it leads compilation error..

Posted by Om Prakash Om    2013-12-31 08:51:32

answer is 'E' because the overrided method " isExecuted();" while defining, declared with protected in child class that is  "AbstractTest" which is not there when declared in parent class that is "AbstractIt" class.....

Posted by Sai Teja    2013-12-31 11:18:43

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

Posted by Merit Campus    2014-01-01 05:10:43

© meritcampus 2019

All Rights Reserved.

Open In App