πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      What is the purpose of the 'static' keyword in

      Java?
      A To make a variable's value constant and unmodifiable Correct Answer Incorrect Answer
      B To indicate that a member belongs to the class itself rather than to instances of the class Correct Answer Incorrect Answer
      C To prevent a class from being subclassed Correct Answer Incorrect Answer
      D To declare a variable that retains its value between method calls only Correct Answer Incorrect Answer
      E To restrict access to a method from outside the package Correct Answer Incorrect Answer

      Solution

      A static variable/method belongs to the class, not to any specific object. Static variables are shared across all instances. Static methods can be called without creating an object (e.g., Math.sqrt()). A static variable like interestRate in a BankAccount class would be shared by all account objects. 'final' makes a variable constant. 'final class' prevents subclassing. 'protected' restricts access.

      Practice Next

      Relevant for Exams:

      ask-question