A

Admin • 833.24K Points
Coach

Q. What will be the output for the below code?
public class Test{
public static void main(String[] args){
byte i = 128;
System.out.println(i);
}
}

  • (A) 128
  • (B) 0
  • (C) Compilation fails with an error at line 3
  • (D) Compilation fails with an error at line 3 D. Compilation fails with an error at line 4
  • Correct Answer - Option(C)
  • Views: 41
  • Filed under category Java
  • Hashtags:

Explanation by: Admin

byte can only hold up to 127. So compiler complain about possible loss of precision.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.