Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

What will happen when you compile and run the following code?

  1. public class Q1 {
  2.  public static void main(String args[]){
  3.   int i = 010;
  4.   System.out.println(i);
  5.  }
  6. }
a. Program will give compilation error
b. Program will give runtime error
c. Program will print 8
d. None of the above

  Answer:

C is the correct choice. Program will not give compile time or runtime error. If int variable starts with 0, the number is considered to be octal and thus, it will print 8 instead of 10 when run.
No votes yet
Share this

Post new comment