What is output of following code package r4r.co.in.core.java; public class HelloWorld { int i = 0; public static void main(String args[]) { System.out.println(i); new HelloWorld(); } static { final static int i=0; i = 10; System.out.println(i); } }

What is output of following code package r4r.co.in.core.java; public class HelloWorld { int i = 0; public static void main(String args[]) { System.out.println(i); new HelloWorld(); } static { final static int i=0; i = 10; System.out.println(i); } }

The above program give 3 errors in compilation : 
  1. a non-static variable i can be referenced from a static context in the main method. 
  2. modifier static is not allowed in the static initialization block.
  3. can\'t assign a value to final variable.

By:Jalees
Date:2016-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher