Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- public class Q2 {
- static int class_var = 2;
- public Q2(){
- class_var = 5;
- }
- public static void main(String args[]){
- System.out.println(class_var);
- }
- }
b. 5
c. Compile time error
d. None of the above.
Answer:
A is the correct choice. class_var is declared as a static variable and initialized to 2. When main is called, it's value would be 2 since there is no object of the class created, so constructor is not called.

Post new comment