Which of the following is true about the ‘static’ keyword in Java?

Java MCQ: Which of the following is true about the ‘static’ keyword in Java?

a) Static methods belong to the class, not instances
b) Static methods can access instance variables directly
c) Static methods can be abstract
d) Static methods can override instance methods

Answer:

a) Static methods belong to the class, not instances

Explanation:

In Java, static methods are associated with the class itself rather than with any specific instance of the class. This means that they can be called without creating an instance of the class. For example, ClassName.methodName() can be used to call a static method.

Static methods cannot directly access instance variables or instance methods, because they are not tied to any particular object. They can only access other static members (variables or methods) of the class.

Understanding the static keyword is important for designing methods that should be available at the class level rather than at the object level.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top