Which of the following statements is/are true regarding JAVA? A. Constants…
2022
Which of the following statements is/are true regarding JAVA? A. Constants that cannot be changed are declared using the “Static” keyword. B. A class can inherit only one class, but it can implement multiple interfaces.
- A.
A is true
- B.
B is true
- C.
Both (A) and (B) are true
- D.
Neither (A) nor (B) is true
Attempted by 158 students.
Show answer & explanation
Correct answer: B
Constants in Java (Statement A)
The
finalKeyword: This is the actual "constant" modifier. Once afinalvariable is initialized, it cannot be reassigned.The
staticKeyword: This simply means the variable belongs to the class itself rather than a specific instance (object).The Difference: You can have a
staticvariable that is notfinal(it's shared by all objects but can change), and you can have afinalvariable that is notstatic(each object has its own constant value).
2. Inheritance and Interfaces (Statement B)
Java uses a very specific model to keep code clean and manageable:
Classes: A class can extend only one other class. This prevents the "Diamond Problem" where a class might inherit conflicting methods from two different parents.
Interfaces: A class can implement any number of interfaces. This allows for great flexibility because interfaces only define "what" a class must do, not "how" it does it (until the introduction of default methods, but the inheritance rule remains the same).