Search This Blog

Loading...

Tuesday, August 9, 2011

Core Java: Miscellaneous OOP's concepet in java

*********** First 1. **************

// Q. 1) What will be the output ?
public class Hello1 {

public static void main (String args[]) {

System.out.println (A.a);
System.out.println (B.b);
}

}

// Q. 2) Why static block of class 'A' doesn't execute ?
// Q. 3) Why class 'A' doesn't load when we access the final variable 'a' ?
class A {

static {
System.out.println ("Hi, This is static block of class 'A' !!!!");
}

public static final int a = 100;
}

// Q. 4) Shall the following class 'B' compile successfully, Why?
class B {

static {
System.out.println ("Hi, This is static block of class 'B' !!!!");
b = 200;
}

public static final int b;
}

*******************************************************************

0 comments:

Post a Comment