Single Choice Easy

QWhat is the purpose of "static" keyword in JAVA?

ID: #22220 static Keyword in Java 117 views
Question Info
#22220Q ID
EasyDifficulty
static Keyword in JavaTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A It allows the method to be called without creating an instance of the class.
  • B It makes the method execute faster.
  • C Static keyword prevents the method from being overridden.
  • D All of these.
Correct Answer

Explanation

It allows the method to be called without creating an instance of the class.

Explanation:

In Java, the static keyword is used for:

  1. Static Methods and Variables:

    • Methods: A static method belongs to the class rather than instances of the class. This means you can call the method directly on the class itself without needing to create an instance.


class Example {
    static void staticMethod() {
        System.out.println("Static method");
    }
}

// Calling the static method without creating an instance
Example.staticMethod();

No Previous No Next

Share This Question

Challenge a friend or share with your study group.