Friday, February 18, 2011

Initialization is must in java(@Compile time itself)

Consider the following program:

public class Test {
public static void main (String args []) {
int age;
age = age + 1;
System.out.println("The age is " + age);
}
}
So what will be the outcome of this program?? 

A. Compiles and runs with no output
B. Compiles and runs printing out The age is 1
C. Compiles but generates a runtime error
D. Does not compile
E. Compiles but generates a compile time error


Correct answer is D. So java makes it important to initialize.

No comments:

Post a Comment

Chitika