Inheritance in Object-Oriented Programming
Which of the following is the correct way to define a subclass 'Dog' that inherits from a superclass 'Animal' in Java?
class Dog inherits Animal {}
class Dog extends Animal {}
class Dog implements Animal {}
class Dog includes Animal {}
Consider classes A, B, and C. A is the superclass of both B and C. If class D attempts to inherit from both B and C, and both B and C have a method with the same name, what problem might arise?
Increased memory usage
The diamond problem leading to ambiguity in method resolution
Compiler errors due to conflicting variable names
Slower runtime performance due to increased complexity
Given the following code snippet, which class is the superclass?
java
class Vehicle {}
class Car extends Vehicle {}
Car
Vehicle
Both Car and Vehicle
Neither Car nor Vehicle
What is the correct syntax to declare class Car
as a subclass of class Vehicle
?
class Car : Vehicle {}
class Car extends Vehicle {}
class Car implements Vehicle {}
class Car inherits Vehicle {}
Consider a scenario with classes 'Shape', 'TwoDimensionalShape', and 'Circle'. 'TwoDimensionalShape' inherits from 'Shape', and 'Circle' inherits from 'TwoDimensionalShape'. Which is the most appropriate superclass for 'TwoDimensionalShape'?
Circle
TwoDimensionalShape
Shape
None of the above
Fill in the blank to correctly establish inheritance: class SportsCar ____ Car {}
inherits
extends
implements
includes
Given the following class hierarchy, write the class headers for classes A, B, and C, where A is the superclass of B, and B is the superclass of C.
A {}; B extends A {}; C extends B {}
A extends B {}; B extends C {}; C {}
A extends B extends C {}
A implements B implements C {}

How are we doing?
Give us your feedback and let us know how we can improve
Why does Java not allow a class to inherit from multiple superclasses directly?
To simplify the syntax of class declarations.
To avoid the diamond problem.
To improve memory management.
To enforce strict encapsulation.