Which of the below given statement(s) is/are false?
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Which of the below given statement(s) is/are false?
I) In Has-A relationship an object of one class is created as data member in another class the relationship between these two classes is Has-A.
II) We can inherit the final method but cannot override the final method inside the child class.
III) A class with static modifier cannot be inherited.
Show answer & explanation
Statement I is TRUE: Has-A relationship represents composition/aggregation where one class contains an object of another class as a data member. Statement II is TRUE: final methods can be inherited but cannot be overridden in child classes (this is the purpose of the final keyword). Statement III is FALSE: in Java, only inner classes can be declared static; top-level classes cannot have the static modifier and this syntax is invalid. Therefore, only statement (III) is false.
Step-by-step Derivation:
Evaluate each statement:
Statement I - Has-A Relationship:
Has-A (composition/aggregation) occurs when class B has an object of class A as a member variable.
Example: class Car { Engine engine; } — Car HAS-A Engine.
This statement is TRUE.
Statement II - Final Methods:
When a method is marked final, it cannot be overridden in subclasses, but it is still inherited.
Example:
class Parent {
final void display() { System.out.println("Parent"); }
}
class Child extends Parent {
// Can call display() but CANNOT override it
// void display() { } // COMPILATION ERROR
}
This statement is TRUE.
Statement III - Static Class Modifier:
In Java, the static keyword cannot be applied to top-level classes. Only inner classes (nested classes) can be declared static.
Invalid syntax: static class MyClass { } (if MyClass is top-level)
Valid syntax: class Outer { static class Inner { } }
This statement is FALSE.
Conclusion: Only statement (III) is false.