Skip to main content
Typos and markup corrections; added static methods and inheritance related tags
Source Link
class A { static{ get(); } static void get(){ System.out.println("HELLO"); } } class B extends A { public static void main(String[] args) { } } 

Ouput -
HELLO
HowOutput:

HELLO

How is static method of class AA getting called.I I can understand static method of B getingB getting called but not of AA.

class A { static{ get(); } static void get(){ System.out.println("HELLO"); } } class B extends A { public static void main(String[] args) { } } 

Ouput -
HELLO
How is static method of class A getting called.I can understand static method of B geting called but not of A.

class A { static{ get(); } static void get(){ System.out.println("HELLO"); } } class B extends A { public static void main(String[] args) { } } 

Output:

HELLO

How is static method of class A getting called. I can understand static method of B getting called but not of A.

Source Link

Static method in inheritance

class A { static{ get(); } static void get(){ System.out.println("HELLO"); } } class B extends A { public static void main(String[] args) { } } 

Ouput -
HELLO
How is static method of class A getting called.I can understand static method of B geting called but not of A.