Inheritance In Java
Method Overriding in Java
❖ If subclass (child class) has the same method as
declared in the parent class, it is known as method
overriding in Java.
Super Class
❖ Super is a keyword of Java which refers to the immediate
parent of a class and is used inside the subclass method
definition for calling a method defined in the superclass.
❖ A superclass having methods as private cannot be called.
Only the methods which are public and protected can be
called by the keyword super.
Run Time Polymorphism Or Dynamic Method dispatch
● It is a process in which a call to an overridden method is resolved at runtime
rather than compile-time.
● In this process, an overridden method is called through the reference variable
of a superclass. The determination of the method to be called is based on the
object being referred to by the reference variable.
● If the reference variable of Parent class refers to the object of Child class, it is
known as upcasting.
Example of Java Runtime Polymorphism
Dynamic Method Look UP
● Dynamic method lookup refers to the process by which a
programming language or runtime environment
determines the appropriate method or function to execute
at runtime, based on the actual type or class of an object.
● In other words, the method or function to be called is
resolved dynamically during program execution rather
than being determined at compile-time.
Example:-
class Shape:
def draw(self):
print("Drawing a generic shape")
class Circle(Shape):
def draw(self):
print("Drawing a circle")
class Square(Shape):
def draw(self): In this example, the draw method is called
print("Drawing a square") on objects of different types (Circle and
# Dynamic method lookup
Square). The dynamic method lookup
shapes = [Circle(), Square()] ensures that the appropriate draw method
for shape in shapes: associated with the actual type of each
[Link]()
object is invoked at runtime.