Inheritance and Polymorphism
Questions and Answers Graded A+
What is the purpose of the `final` keyword in inheritance?
✔✔ The `final` keyword prevents a method from being overridden or a class from being
inherited.
Can an interface extend another interface?
✔✔ Yes, an interface can extend another interface using the `extends` keyword.
What is the difference between an abstract class and an interface?
✔✔ An abstract class can have both abstract and concrete methods, while an interface can only
have abstract methods (before Java 8).
What happens when a subclass does not provide an implementation for an abstract method from
its superclass?
✔✔ The subclass must be declared abstract or implement all abstract methods.
1
,Is method overloading an example of polymorphism?
✔✔ Yes, method overloading is an example of compile-time polymorphism.
Can an interface have a constructor in Java?
✔✔ No, interfaces cannot have constructors because they cannot be instantiated.
What happens if two interfaces have methods with the same name and a class implements both
interfaces?
✔✔ The class must provide an implementation for the method, resolving any conflicts.
Can a subclass access a protected member of its superclass?
✔✔ Yes, a subclass can access protected members of its superclass.
Can a final method be overloaded?
✔✔ Yes, a final method can be overloaded, but it cannot be overridden.
Does Java support multiple inheritance using classes?
✔✔ No, Java does not support multiple inheritance using classes to avoid ambiguity.
2
,Can an abstract class have concrete methods?
✔✔ Yes, an abstract class can have both abstract and concrete methods.
What is dynamic method dispatch?
✔✔ Dynamic method dispatch is the mechanism by which method calls are resolved at runtime
based on the object's actual type.
Can a subclass inherit a `final` class?
✔✔ No, a `final` class cannot be inherited.
What is inheritance in Java?
✔✔ Inheritance is a mechanism that allows one class to inherit fields and methods from another
class.
What keyword is used to inherit a class in Java?
✔✔ The `extends` keyword is used to inherit a class.
3
, Can a Java class inherit from multiple classes?
✔✔ No, Java does not support multiple inheritance with classes. A class can inherit from only
one class.
What is the superclass in inheritance?
✔✔ The superclass is the parent class from which other classes inherit properties and methods.
What is the subclass in inheritance?
✔✔ The subclass is the child class that inherits properties and methods from a superclass.
What is polymorphism in Java?
✔✔ Polymorphism is the ability of an object to take multiple forms, allowing the same method
to have different implementations.
What are the two types of polymorphism in Java?
✔✔ Compile-time polymorphism (method overloading) and runtime polymorphism (method
overriding).
4