1/14
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is polymorphism in Java?
The ability of an object to take many forms, typically allowing a single interface to represent different types.
What are the two types of polymorphism in Java?
Compile-time (static) polymorphism and Run-time (dynamic) polymorphism.
What is compile-time polymorphism?
Polymorphism achieved through method overloading during compilation.
What is run-time polymorphism?
Polymorphism achieved through method overriding, determined at runtime.
What is method overloading?
Defining multiple methods in the same class with the same name but different parameters.
What is method overriding?
Redefining a method in a subclass that already exists in the parent class.
Which keyword is used for method overriding?
@Override annotation is used to indicate method overriding.
What is dynamic method dispatch?
The process of resolving method calls at runtime based on the object’s actual type.
Can static methods be overridden?
No, static methods belong to the class and not to instances.
Can constructors be overloaded?
Yes, constructors can be overloaded in the same class with different parameter lists.
Can you override private methods?
No, private methods are not visible to subclasses, so they cannot be overridden.
What is the advantage of polymorphism?
Improves code reusability, flexibility, and maintainability.
What is an example of polymorphism in Java libraries?
The List
interface can be implemented by ArrayList
, LinkedList
, etc.
What is late binding?
Binding which happens at runtime, used in dynamic polymorphism.
How does Java achieve run-time polymorphism?
Through method overriding and object reference pointing to subclass objects.