Basics of Inheritance
Overriding and Overloading
Polymorphism Concepts
Constructors and Initialization
Code Tracing
100

What keyword is used to inherit a class?

What is "extends"?

100

What is method overriding?

What is the process of redefining a method in a subclass?

100

What does polymorphism mean in Java?

What is the ability of a single action to be performed differently based on the object?

100

Can a subclass call its superclass’s constructor?

Yes, by using the "super" keyword.

100

Predict the output: Animal a = new Dog(); a.speak();

Output depends on the speak method defined in Dog. If overridden, it calls the subclass method.

200

What is the superclass in Java?

The superclass is the class being inherited from

200

Can a private method be overridden? Why or why not?

No, private methods are not inherited and cannot be overridden.

200

Give an example of runtime polymorphism.

Example: Parent obj = new Child(); obj.method();

200

What is the purpose of a no-argument constructor?

A no-argument constructor provides a default way to instantiate an object.

200

Given a superclass and a subclass, which constructor is called first when creating a subclass object?

The constructor of the superclass is called first before the subclass constructor.

300

True or False: Java supports multiple inheritance.

What is false?

300

What is method overloading?

The creation of methods with the same name but different parameters.

300

What is dynamic method dispatch?

Dynamic method dispatch refers to the process of resolving a method call at runtime.

300

How are constructors invoked in an inheritance chain?

Constructors are invoked in the inheritance chain from superclass to subclass.

300

Write a simple code snippet demonstrating method overriding.

class Animal {    

void speak() { 

System.out.println("Animal speaks"); 

} class Dog extends Animal {    

void speak() 

{ System.out.println("Dog barks"); 

}

}

400

What is the purpose of the super keyword?

The "super" keyword is used to access members (methods or variables) of the superclass.

400

What happens if the return types of overridden methods differ?

A compile-time error occurs because the signatures must match exactly.

400

How does polymorphism enhance maintainability?

Polymorphism allows code to work with different object types interchangeably, making updates easier.

400

What happens if a superclass has no default constructor?

A compilation error occurs if the subclass does not explicitly call a valid superclass constructor.

400

What is the output when a final method is called in a subclass object?

The final method executes as defined in the superclass, regardless of the subclass object.

500

Explain the difference between is-a and has-a relationships

An "is-a" relationship denotes inheritance (e.g., Dog is-a Animal). A "has-a" relationship denotes composition (e.g., Car has-a Engine).

500

Why must the overriding method have the same signature as the method in the superclass?

Because the overriding method needs to maintain compatibility with the superclass version.

500

Can static methods exhibit polymorphism? Why or why not?

No, static methods belong to the class, not the object, and cannot exhibit polymorphism.

500

Explain the order of constructor execution in a multi-level inheritance hierarchy.

Constructors are executed from the top of the hierarchy (superclass first) down to the subclass.

500

Write a code involving a superclass reference pointing to a subclass object.


Parent p = new Child();

p.method();

M
e
n
u