public class MyClass { final int i ; public static void main(String[] arguments) { System.out.println(new MyClass().i); } } ----------------------------- Fails to compile saying that i is not initialized. Why is it so when i is an instance variable? Thanks
class MyClass { public static void main (String args[]) { String s1[] = new String[5]; String str = s1[0].toUpperCase(); System.out.println(str); } } ---------------------------------------------- this gives null pointer exception.Why is it so? Thanks
Hi, An instance final variable has to be initialized before being used inside a constructor or an instance initializer. When constructing your String array, it was initiliazied to null and therefore you're trying to use null in a case where an object is required. That triggers the NullPointerException Hope this helps
Whatever doesn't kill us ...<br />Is probably circling back for another try.<br />SCJP 1.4