1
Java / Re: Java quiz series
« on: December 02, 2013, 04:28:02 pm »Correct.Code: (Java) [Select]public class Home {
private static Home home = new Home();
private static int DEFAULT_NR_OF_ROOMS = 4;
private final int rooms;
public Home() {
rooms = DEFAULT_NR_OF_ROOMS - 1;
}
public static void main(String[] args) {
System.out.println(home.rooms);
}
}
What does this print and why?
Well the problem is with int rooms because it is final and at declaration it is not assigned any value. Final variables must be assigned values at their declaration.