What will be the result of compilation and execution of the following code?

public class Test {
    static void methodA(Long l) {
    static void methodB(Object o) {
        Byte b = (Byte) o;
    public static void main(String[] args) {
        byte b = 5;
        methodA(b);  // 1
        methodB(b);  // 2
The compiler does not apply widening + autoboxing when calling a method, but it can apply them in reversed order.
For methodB only boxing has to be applied because Byte is an Object.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes