Maruthi Krishna has Published 952 Articles

Is it possible to use this keyword in static context in java?

Maruthi Krishna

Maruthi Krishna

Updated on 30-Jul-2019 22:30:26

907 Views

A static method or, block belongs to the class and these will be loaded into the memory along with the class. You can invoke static methods without creating an object. (using the class name as reference).Whereas "this" in Java acts as a reference to the current object. But static contexts(methods and ... Read More

When and where static blocks are executed in java?

Maruthi Krishna

Maruthi Krishna

Updated on 30-Jul-2019 22:30:26

2K+ Views

A static block is a block of code with a static keyword. In general, these are used to initialize the static members. JVM executes static blocks before the main method at the time of class loading.Example Live Demopublic class MyClass {    static{       System.out.println("Hello this is a static ... Read More

Advertisements