Home / Programming MCQs / JAVA MCQs / Question

J

Jatin Dubey • 3.78K Points
Extraordinary

Q. What is the output for the below code ? 

Code:
1. public class Test{
2.       public static void main(String[] args){
3.             int i = 010;
4.             int j = 07;
5.             System.out.println(i);
6.             System.out.println(j);
7.       }
8. }
(A) 8 7
(B) 10 7
(C) Compilation fails with an error at line 3
(D) Compilation fails with an error at line 5
Explanation by: Jatin Dubey
By placing a zero in front of the number is an integer in octal form. 010 is in octal form so its value is 8

You must be Logged in to update hint/solution

Discusssion

Login to discuss.