Menu
Question Index
...

What will be the output of the following program?

public class Rough1 {
    public static void main(String[] args) {
            byte b = getStatusValue(255);
            System.out.println(b);
            b = Rough2.getStatusValue(122);
            System.out.println(b);
    }
    static byte getStatusValue(Object obj){
        if (obj != null)
            return 127;
        else
            return -1;
    }
}
class Rough2 extends Rough1 {
    static byte getStatusValue(Object obj) {
        if (obj != null)
            try {
                return (Byte) obj;
            } catch (Exception e) {
                System.out.println("Can't type cast");
            }
        else
            return -1;
        return (byte) 255;
    }
}


-1
122
127
Can't type cast
-1
127
122
-1
Can't type cast
-1
Compilation Error or Runtime Error

Doubts

Problems

Topic: Try Catch Block 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