Why is Java called a completely Object Oriented Language?
Why is the main() method definition always public static?
The 'public' Keyword:
The 'static' Keyword:
The keyword 'static' can be used before both variable and method instances of a class.
The situations where we need to use a class before defining its objects are the cases where we define a method to be static.
Unlike other earlier OOP languages like C++, it is impossible to create a program without defining a class in Java. Hence, it is called as completely Objec Oriented Language.
Why is the main() method definition always public static?
The 'public' Keyword:
The keyword 'public' is used when we want a method of a class to be accessed by any other class or code in any part of the program. Hence, as we know that main() method should be given open access to the codes in any part of the program, it is given public access.
The 'static' Keyword:
The keyword 'static' can be used before both variable and method instances of a class.
The situations where we need to use a class before defining its objects are the cases where we define a method to be static.
Therefore, it is clear that the main() method should always be declared static as we need to use the main class without creating its object instances.
No comments:
Post a Comment