0% found this document useful (0 votes)
16 views

Unit II

Unit II OOPS

Uploaded by

Balamurugan V
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Unit II

Unit II OOPS

Uploaded by

Balamurugan V
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

UNIT II

INHERITANCE, PACKAGES AND INTERFACES


Overloading Methods – Objects as Parameters – Returning Objects –Static, Nested and
Inner Classes. Inheritance: Basics– Types of Inheritance -Super keyword -Method
Overriding – Dynamic Method Dispatch –Abstract Classes – final with Inheritance.
Packages and Interfaces: Packages – Packages and Member Access –Importing
Packages – Interfaces.

Overloading Methods
Definition: In Java, Method Overloading allows different methods to have the same name,
but different signatures where the signature can differ by the number of input parameters or
type of input parameters, or a mixture of both.
Example:
Example of Method Overloading Output
public class Sum { 30
public int sum(int x, int y) { return (x + y); } 60
31.0
public int sum(int x, int y, int z)
{
return (x + y + z);
}

public double sum(double x, double y)


{
return (x + y);
}

public static void main(String args[])


{
Sum s = new Sum();
System.out.println(s.sum(10, 20));
System.out.println(s.sum(10, 20, 30));
System.out.println(s.sum(10.5, 20.5));
}
}
Different Ways of Method Overloading in Java
 Changing the Number of Parameters.
 Changing Data Types of the Arguments.
 Changing the Order of the Parameters of Methods
1. Changing the Number of Parameters
Method overloading can be achieved by changing the number of parameters while passing to
different methods.
// Java Program to Illustrate Method Overloading Output
// By Changing the Number of Parameters
import java.io.*; Product of the two integer value :2
class Product { Product of the three integer value :6
public int multiply(int a, int b)
{
int prod = a * b;
return prod;
}
public int multiply(int a, int b, int c)
{
int prod = a * b * c;
return prod;
}
}

class GFG {
public static void main(String[] args)
{

Product ob = new Product();


int prod1 = ob.multiply(1, 2);
System.out.println( "Product of the two integer value :" + prod1);
int prod2 = ob.multiply(1, 2, 3);
System.out.println( "Product of the three integer value :" + prod2);
}
}
2. Changing Data Types of the Arguments
In many cases, methods can be considered Overloaded if they have the same name but have
different parameter types, methods are considered to be overloaded.
// Java Program to Illustrate Method Overloading Output
// By Changing Data Types of the Parameters
import java.io.*; Product of the three integer value :6
Product of the three double
class Product { value :6.0
public int Prod(int a, int b, int c)
{
int prod1 = a * b * c;
return prod1;
}

public double Prod(double a, double b, double c)


{
double prod2 = a * b * c;
return prod2;
}
}
class GFG {
public static void main(String[] args)
{
Product obj = new Product();

int prod1 = obj.Prod(1, 2, 3);


System.out.println( "Product of the three integer value :" + prod1);

double prod2 = obj.Prod(1.0, 2.0, 3.0);


System.out.println( "Product of the three double value :" + prod2);
}
}
3. Changing the Order of the Parameters of Methods
Method overloading can also be implemented by rearranging the parameters of two or more
overloaded methods. For example, if the parameters of method 1 are (String name, int
roll_no) and the other method is (int roll_no, String name) but both have the same name, then
these 2 methods are considered to be overloaded with different sequences of parameters.
// Java Program to Illustrate Method Overloading Output
// By changing the Order of the Parameters
import java.io.*; Product of the three integer value :6
class Student { Product of the three double
// Method 1 value :6.0
public void StudentId(String name, int roll_no)
{
System.out.println("Name :" + name + " " + "Roll-No :" + roll_no);
}

// Method 2
public void StudentId(int roll_no, String name)
{
System.out.println("Roll-No :" + roll_no + " " + "Name :" +
name);
}
}
class GFG {
// Main function
public static void main(String[] args)
{
Student obj = new Student();
obj.StudentId("Spyd3r", 1);
obj.StudentId(2, "Kamlesh");
}
}
Object as Parameters
 Java is strictly pass-by-value. But the scenario may change when the parameter
passed is of primitive type or reference type.
o If we pass a primitive type to a method, then it is called pass-by-value or call-
by- value.
o If we pass an object to a method, then it is called pass-by-reference or call-by-
reference.
 Object as a parameter is a way to establish communication between two or more
objects of the same class or different class as well.
Java Program to demonstrate Object as a Parameter Output
public class ObjDemo { F:\test>javac ObjDemo.java

F:\test>java Demo
int height;
The area is 276
int width;

ObjDemo(int h,int w)

height=h;

width=w;

void area(ObjDemo o)

int result (height+o.height)*(width+o.width);

System.out.println("The area is "+result);

class Demo {

public static void main(String args[])


{

ObjDemo obj1 = new ObjDemo (2,3);

ObjDemo obj2= new ObjDemo(10,20);

obj1.area(obj2);

}}

Returning Objects

 We can return an object from a method. The data type for such method is a class type.
Example Program Output
public class Sample Value : 20
{
private int value;

public Sample(int i)
{
value = i;
}

/**
* The makeTwice method returns a Sample
object
* containing the value twice the passed to it.
*/
public Sample makeTwice()
{
Sample temp = new Sample(value * 2);

return temp;
}

public void show()


{
System.out.println("Value : " + value);
}
}
public class ReturnObjectDemo
{
public static void main(String[] args)
{
Sample obj1 = new Sample(10);
Sample obj2;

// The makeTwice method returns a reference


obj2 = obj1.makeTwice();
obj2.show();
}
}

Inheritance: Basics
 Definition: Inheritance is a mechanism in Java by which derived class can
borrow the properties of base class and at the same time the derived class may
have some additional properties.
Advantages of Inheritance
One of the key benefits of inheritance is to minimize the amount of duplicate code in an
application by sharing common code amongst several subclasses.
1. Reusability: The base class code can be used by derived class without any need to
rewrite the code.
2. Extensibility: The base class logic can be extended in the derived classes.
3. Data hiding: Base class can decide to keep some data private so that it cannot be
altered by the derived class.
4. Overriding: With inheritance, we will be able to override the methods of the base
class so that meaningful implementation of the base class method can be designed in the
derived class

Concept of Base and Derived Class

 The inheritance is a mechanism in which the child class is derived from a parent class.
 This derivation is using the keyword extends.
 The parent class is called base class and child class is called derived class.
 For example

Class A
This is Base class
{
………
}
Class B extends A
This is Derived class
{
……….// uses properties of A
}

Inheritance is represented diagrammatically as follows

Types of Inheritance
1. Single Inheritance
2. Multi-level Inheritance
3. Hierarchical Inheritance
4. Multiple Inheritance

Single Inheritance public class A{

………..
}
public class B extends A{
……….
}
Multilevel Inheritance public class A{………………………….}
public class B extends A{…………….}
public class C extends B{……………}
Hierarchical Inheritance public class A{………………………….}
public class B extends A{…………….}
public class C extends A{……………}

Multiple Inheritance public class A{………………………….}


public class B {…………….}
public class C extends A,B{……………}
//Java does not support multiple inheritance

Single Inheritance
 In single inheritance there is one parent per derived class.
 This is most common form of inheritance.

Example Program for Single Inheritance Output


class Parent D:\java1>java Inherit
{ 20
int a; CHILD
void display() 0
{
System.out.println("PARENT");
}
}
class Child extends Parent{
int b=20;
void show()
{
System.out.println("CHILD");
}
}
class Inherit{
public static void main(String args[]){
Child c=new Child();
System.out.println(c.b);
c.show();
System.out.println(c.a);
}
}

Multi-level Inheritance
 When a derived class is derived from a base class which itself is a derived class then
that type of inheritance is called multilevel inheritance.

Example Program for Multilevel Inheritance Output


class A{ D:\java1>javac Multilevel.java
int a=20;
void display() D:\java1>java Multilevel
{ C
System.out.println("A"); B
} A
}
class B extends A
{
int b=30;
void show()
{
System.out.println("B");
}
}
class C extends B
{
int c=50;
void dis()
{
System.out.println("C");
}}
class Multilevel{
public static void main(String args[])
{
C obj=new C();
obj.dis();
obj.show();
obj.display();
}
}

Hierarchical Inheritance
If a number of classes are derived from a single base class, it is called hierarchical
inheritance.

Example Program for Hierarchical Inheritance Output


class A D:\java1>javac Hierarchy.java
{
int a=20; D:\java1>java Hierarchy
void display() C
{ A
System.out.println("A"); B
} A
}
class B extends A
{
int b=30;
void show()
{
System.out.println("B");
}
}
class C extends A
{
int c=40;
void dis()
{
System.out.println("C");
}
}
class Hierarchy
{
public static void main(String args[])
{
C obj1=new C();
obj1.dis();
obj1.display();
B obj2=new B();
obj2.show();
obj2.display();
}
}
Multiple Inheritance
 In multiple Inheritance the derived class is derived from more than one base class.
 Java does not support multiple inheritances due to ambiguity.
 Java does not implement multiple inheritance directly but it makes use of the concept
called interfaces to implement multiple inheritance

Program to implement Multiple Inheritance Output


import java.io.*; Compilation Error

class Parent1 {

// Method inside first parent class


void fun() {

// Print statement if this method is called


System.out.println("Parent1");
}
}

class Parent2 {
void fun() {

// Print statement if this method is called


System.out.println("Parent2");
}
}

class Test extends Parent1, Parent2 {

// Main driver method


public static void main(String args[]) {

// Creating object of class in main() method


Test t = new Test();

// Trying to call above functions of class where


// Error is thrown as this class is inheriting
// multiple classes
t.fun();
}
}

Method Overriding
 If the same method is defined in both the superclass and the subclass, then the method
of the subclass class overrides the method of the superclass. This is known as method
overriding.
 Rules for Method Overriding in Java
o The method name should be common and the same as it is in the parent
class.
o The method signature (parameter list, return type) in the method must be
the same as in the parent class.
o There must be an inheritance connection between classes.
o If it declared the methods as static or final, then those methods cannot be
overridden.
Example Program for Method Overriding Output
class Parent{ CHILD METHOD
void display()
{
System.out.println("PARENT METHOD");
}
}
class Child extends Parent
{
void display()
{

System.out.println("CHILD METHOD");
}
}
class Override{
public static void main(String args[]){
Child c=new Child();
c.display();
}
}
Example Program for Method Overriding using Output
super class
class Parent{ D:\java1>javac Override.java
void display()
{ D:\java1>java Override
System.out.println("PARENT METHOD"); PARENT METHOD
} CHILD METHOD
}
class Child extends Parent
{
void display()
{
super.display();
System.out.println("CHILD METHOD");
}
}
class Override{
public static void main(String args[]){
Child c=new Child();
c.display();
}
}
Java Program for Method Overriding Output
class A value of a:15
{ value of b:20
int a=0;
void fun(int i) The value of c= 300
{
this.a=i;
}
}
class B extends A
{
int b;
void fun(int i)
{
int c;
b=20;
super.fun(i+5);
System.out.println("value of a:"+a);
System.out.println("value of b:"+b);
c=a*b;
System.out.println("The value of c= "+c);
}
}
class OverrideDemo
{
public static void main(String args[])
{
B obj_B =new B();
obj_B.fun(10);//function re-defined in derived class
}
}

In above program, there are two class - class A and class B. The class A acts as a
superclass and the class B acts as a subclass. In class A, a method fun is defined in which
the variable a is assigned with some value. In the derived class B, we use the same function
name fun in which, we make use of super keyword to access the variable a and then it is
multiplied by b and the result of multiplication will be printed.
Super Keyword
 Super is a keyword used to access the immediate parent class from subclass
 There are three ways by which the keyword super is used.

1. The super () is used to invoke the class variable of immediate parent class.
Program Output
class A 10
{
int x=10;
}
class B extends A
{
int x=20;
void display()
{
System.out.println(super.x);
}
public static void main(String args[])
{
B obj =new B();
obj.display();
}
}

2. The super () is used to access the class method of immediate parent class.
Program Output
class A Method: Class A
{
void fun()
{
System.out.println("Method: Class A");
}
}
class B extends A
{
void fun()
{
System.out.println("Method: Class B");
}
void display()
{
super.fun();
}
public static void main(String args[])
{
B obj =new B(); obj.display();
}
}

3. The super () is used to invoke the immediate parent class constructor.


Program Output
class A Constructor of Class A
{
Constructor of Class B
A()
{

System.out.println("Constructor of Class A");


}
class B extends A
{
B()
{
super();
System.out.println("Constructor of Class B");
}
public static void main(String args[])
{
B obj=new B();
}
}

Differences between Method Overloading and Method Overriding


Method Overloading Method Overriding
 The method overloading occurs at  The method overriding occurs at the
compile time. run time or execution time.
 In case of method overloading  In function overriding the number of
different number of parameters can parameters that are passed to the
be passed to the function. function are the same.
 The overloaded functions may have  In method overriding all the methods
different return types. will have the same return type.
 Method overloading is performed  Method overriding is normally
within a class. performed between two classes that
have inheritance relationship.

Abstract Classes

 A class which is declared with the abstract keyword is known as an abstract class in
Java. It can have abstract and non-abstract methods (method with the body).
 Rules for Abstract Classes
o An abstract class must be declared with an abstract keyword.
o It can have abstract and non-abstract methods.
o It cannot be instantiated.
o It can have constructors and static methods also.
o It can have final methods which will force the subclass not to change the body
of the method.

Example 1 for Abstract Classes and Methods Output


abstract class Bike{ running safely
abstract void run();
}
class Honda4 extends Bike{
void run(){
System.out.println("running safely");
}
public static void main(String args[]){
Bike obj = new Honda4();
obj.run();
}
}
Example 2 for Abstract Classes and Methods Output
abstract class A D:\java1>javac AbstractMain.java
{
abstract void display(); D:\java1>java AbstractMain
void show() Abstract Method in A
{ SHOW METHOD
System.out.println("SHOW METHOD");
}
}
class B extends A
{
void display()
{
System.out.println("Abstract Method in A");
}
}
class AbstractMain
{
public static void main(String args[])
{
B obj=new B();
obj.display();
obj.show();
}
}
Example 3 for Abstract Classes and Methods Output
abstract class A D:\java1>javac AbstractMain.java
{
abstract void display(); D:\java1>java AbstractMain
} Class A
abstract class B extends A Class B
{
void display()
{
System.out.println("Class A");
}
abstract void show();
}
class C extends B{

void show()
{
System.out.println("Class B");
}
}

class AbstractMain
{
public static void main(String args[])
{
C obj=new C();
obj.display();
obj.show();
}
}

Packages

 A package is a collection of related classes and interfaces.


 To access the classes and interfaces of a package, we should import them to the user
program.
 Java packages classified into following two types:
o Java API packages
o User defined packages
Java API Packages
o Java API provides a large number of classes grouped into different packages
according to functionality
o The following table shows the classes that belong to each package.
Package Name Content
java.lang Language support classes. They include classes for primitive types,
strings, math functions, threads and exceptions
java.util Language utility classes such as Scanner, Vectors, hash tables, random
numbers, date etc.,
java.io Input/Output support classes. They provide facility for the input and
output of date
java.awt Set of classes for implementing graphical user interface. They include
classes for windows, buttons, lists, menus and so on.
java.net Classes for networking. They include classes for communicating with
local computers as well as with internet servers
java.applet Classes for creating and implementing applets
 There are two ways of accessing classes stored in a package
o import package.classname;
o import packagename.*;
 The dot(.) operator separates package and its classes.
 Example:
o import java.util.Scanner;
o Here java is a main package and util is a sub-package. The Scanner is the one
of the class in util package. This statement imports only Scanner class to the
program.
 Example:
o import java.util.*;
o Here * represents all the classes and interfaces. This statement imports all the
classes and interfaces in util package to the program.

Simple example of java package


The package keyword is used to create a package in java.
PackDemo.java
package pack;
public class PackDemo{
public void show()
{
System.out.println("WELCOME TO JAVA PACKAGES");
}
}

Pack1.java
import pack.PackDemo;
class Pack1
{
public static void main(String args[])
{
PackDemo obj=new PackDemo();
obj.show();
}
}
Accessing Packages

There are three ways to access the package from outside the package.

1. import package.*;
2. import package.classname;
3. fully qualified name.

1) Using packagename.*

The import keyword is used to make the classes and interface of another package accessible
to the current package.
Example of package that import the packagename.*
//save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
//save by B.java
package mypack;
import pack.*;
class B{
public static void main(String args[]){
A obj = new A();
obj.msg();
}
}
Output: Hello
2) Using packagename.classname
If you import package.classname then only declared class of this package will be accessible.
Example of package by import package.classname
//save by A.java
package pack;
public class A{
public void msg(){System.out.println("Hello");}
}
//save by B.java
package mypack;
import pack.A;
class B{
public static void main(String args[]){
A obj = new A();
obj.msg();
}
}
Output: Hello

3) Using fully qualified name

If you use fully qualified name then only declared class of this package will be accessible.
Now there is no need to import. But you need to use fully qualified name every time when
you are accessing the class or interface.

Example of package by import fully qualified name


//save by A.java

package pack;

public class A{

public void msg(){System.out.println("Hello");}

//save by B.java

package mypack;

class B{

public static void main(String args[]){

pack.A obj = new pack.A();//using fully qualified name

obj.msg();

Output: Hello

Interfaces

 An interface in Java is a blueprint of a class.


 The interface in Java is a mechanism to achieve abstraction. There can be only
abstract methods in the Java interface, not method body. It is used to achieve
abstraction and multiple inheritance in Java.
Syntax to declare interface:

interface <interface_name>{

// declare constant fields


// declare methods that abstract
// by default.
}
The relationship between classes and interfaces

As shown in the figure given below, a class extends another class, an interface extends
another interface, but a class implements an interface.
Implementing Interfaces

Example for Implementing Interface Output


interface A D:\java1>javac InterfaceAB.java
{ D:\java1>java InterfaceAB
void Adisplay(); A DISPLAY
void Ashow(); A SHOW
}
class AB implements A
{
public void Adisplay()
{
System.out.println("A DISPLAY");
}
public void Ashow()
{
System.out.println("A SHOW");
}
}
class InterfaceAB
{
public static void main(String args[])
{
AB obj=new AB();
obj.Adisplay();
obj.Ashow();
}
}
1. interface printable{ Hello
2. void print();
3. }
4. class A6 implements printable{
5. public void print(){System.out.println("Hello");}
6.
7. public static void main(String args[]){
8. A6 obj = new A6();
9. obj.print();
}
}

Multiple Inheritance through Interfaces

Definition: Multiple inheritance is a mechanism in which the child class inherits the
properties from more than one parent classes.

Java does not support multiple inheritance because it creates ambiguity when the
properties from both the parent classes are inherited in child class or derived class. But it is
supported in case of interface because there is no ambiguity as implementation is provided by
the implementation class.

Implementation of Interfaces Output


interface A D:\java1>javac InterfaceAB.java
{
void Adisplay();
void Ashow(); D:\java1>java InterfaceAB
}
A DISPLAY
interface B
{ A SHOW
void Bdisplay(); B DISPLAY
void Bshow();
B SHOW
}
class AB implements A,B
{
public void Adisplay()
{
System.out.println("A DISPLAY");
}
public void Ashow()
{
System.out.println("A SHOW");
}
public void Bdisplay()
{
System.out.println("B DISPLAY");
}
public void Bshow()
{
System.out.println("B SHOW");
}
}
class InterfaceAB
{
public static void main(String args[])
{
AB obj=new AB();
obj.Adisplay();
obj.Ashow();
obj.Bdisplay();
obj.Bshow();
}
}

Final with Inheritance


 A variable can be declared as final.
 If a particular variable is declared as final then it cannot be modified further.
 The final variable is always a constant.

The Final with Inheritance

The final keyword can be applied at three places -


o For declaring variables
o For declaring the methods
o For declaring the class

Final Variables and Methods


 A variable can be declared as final. If a particular variable is declared as final then it
cannot be modified further. The final variable is always a constant. For example final int
a = 10;
 The final keyword can also be applied to the method. When final keyword is applied to
the method, the method overriding is avoided. That means the methods those are declared
with the keyword final cannot be overridden.
 Consider the following Java program which makes use of the keyword final for declaring
the method
class Test
{
final void fun()
{
System.out.println("\n Hello, this function declared using final");
}
}
class Test1 extends Test
{
final void fun()
{
System.out.println("\n Hello, this another function");
}
}
Output
D:\>javac Test.java

Test.java:10: fun() in Test1 cannot override fun() in Test; overridden method is final final
void fun() absido bene
1 error
Program Explanation
The above program, on execution shows the error. Because the method fun is declared
with the keyword final and it cannot be overridden in derived class.

Final Classes to Stop Inheritance


If we declare particular class as final, no class can be derived from it. Following Java
program is an example of final classes.
final class Test
{
void fun()
{
System.out.println("\n Hello, this function in base class");
}
}
class Test1 extends Test
{
final void fun()
{
System.out.println("\n Hello, this another function");
}
}
Output
D:\>javac Test.java
Test.java:8: cannot inherit from final Test
class Test1 extends Test
1 error
Static, Nested and Inner Classes
o Java Inner class or nested class is a class which is declared inside the class or
interfaces.
o It can access all the members of outer class including private data members and
methods.
o Syntax:
class Java_Outer_class
{
// code
class Java_Inner_Class
{
//code
}
}
Advantages Inner Classes:
o It can access all the members (data members and methods) of outer class including
private.
o Nested classes are used to develop more readable and maintainable code because it
logically group classes and interfaces in one place only.
o Code Optimization: It requires less code to write.
Types of inner classes
o Non-static nested class (inner class)
o Member inner class- A class created within class and outside method.
o Anonymous inner class- A class created for implementing interface or
extending class. Its name is decided by the java compiler.
o Local inner class: A class created within a method.
o Static nested class
o A static class created within class.
o Member inner class
o A class created within class and outside method
o A non-static class that is created inside class but outside a method is called
member inner class.
o Syntax
class Outer
{
//code
class Inner
{
//code
}
}
Member Inner Classes – Program
class Outer
{
private int data = 30;
class Inner
{
void msg()
{
System.out.println(“Data is”+data);
}
}
public static void main(String args[])
{
Outer obj=new Outer();
Outer.Inner in=obj.new Inner();
in.msg();
}
}
Output Member Inner Classes – Program
Data is 30
abstract class Person
Anonymous Inner Classes
{
o A class created for implementing interface or extending class.
abstract void eat();
o Its name is decided by the java compiler.
o In} simple words,
class TestAInner Java.
{
public static void main(String args[])
o Program
{
Person p=new Person(){
void eat()
{
System.out.println(“nice fruits”);
}
};
p.eat();
}
}
Output
Data is 30
Local Inner classes
o A class created within a method.
o If you want to invoke the methods of local inner class, you must instantiate this class
inside the method.
o Program
Local Inner Classes – Program
class Inner1{
private int data = 30;
void display()
{
class Local
{
void msg()
{
System.out.println(data);
}
}
Local l=new Local();
l.msg();
}
public static void main(String args[])
{
Inner1 obj=new Inner1();
obj.display();
}
}
Static Inner Classes – Program
class TestOuter1
Output:
{30
staticclass
Static inner int data=300;
static class Inner
o A static class created within class.
{
o It cannot access non-static date members and methods.
o Itvoid msg() static data members of outer class including private.
can access
{
System.out.println(“Data is”+data);
}
}
public static void main(String args[])
{
TestOuter1.Inner obj=new TestOuter1.Inner();
obj.msg();
}
}
Output:
Data is 300
Dynamic Method Dispatch

The dynamic method dispatch is also called as runtime polymorphism. During the run time
polymorphism, a call to overridden method is resolved at run time. The overridden method is
called using the reference variable of a super class(or base class). The determination of which
method to invoke is done using the object being referred by the reference variable.

Following is a simple Java program that illustrates the Run time polymorphism.

class Base

void display()

System.out.println("\n Base Method Called");

class Derived extends Base

void display() //overridden method

System.out.println("\n Derived Method Called");

public class RunPolyDemo

{
public static void main(String args[])

Base obj=new Derived();//obj is reference to base class // which is referred by the derived
class

obj.display(); //method invocation determined at run time

Output

D:\test>javac RunPolyDemo.java

D:\test>java RunPolyDemo

Derived Method Called

Program Explanation:

In above program, the display method is an overridden method because with the same
signature we are modifying it in its derived class. This method is invoked in the main ().
function using the reference obj. This reference variable is of superclass type. It is assigned
with the reference of Derived class. At run time it is decided that the display method of
derived class should be invoked. Hence it is known as run time polymorphism.

You might also like