The static keyword in java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class. java static methods can be called without creating an object of class. Have we noticed why we write static keyword when defining main it's because program execution begins from main and no object has been created yet. Consider the example below of static methods.
class programming { public static void main(String[] args) { display(); }
static void display() { System.out.println("Java is my favorite programming language."); } }
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
If you apply static keyword with any method, it is known as static method.
class programming {
public static void main(String[] args) {
display();
}
static void display() {
System.out.println("Java is my favorite programming language.");
}
}