Java MCQ: What is the purpose of the ‘static’ keyword in Java?
a) To define a method or variable that belongs to the class
b) To make a class immutable
c) To prevent inheritance
d) To declare a constant
Answer:
a) To define a method or variable that belongs to the class
Explanation:
The static
keyword in Java is used to define methods and variables that belong to the class rather than any instance of the class. This means that static members are shared among all instances of the class.
Understanding the static
keyword is important for designing efficient Java programs where certain methods or variables need to be shared across all instances.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html