Polymorphism Assignment
Polymorphism Assignment
Polymorphism in Java is a concept by which we can perform a single action in different ways.
There are two types of polymorphism in Java: compile-time polymorphism and runtime polymorphism
Runtime polymorphism.
Example-
For example, you have a smartphone for communication. The communication mode you choose could
be anything. It can be a call,
A text message, a picture message, mail, etc. So, the goal is common that is communication, but their
approach is different.
- In Inheritance, using thre concept of polymorphism , Parent and child class method can have its own
implementation.
Class Bank{
}
Class ICICI extends Bank{
Bank b;
B=new SBI();
B=new ICICI();
B=new AXIS();
Output—
Run time polymorphism where at run time we came to know which method is going to invoke
6) What is Upcasting
Upcasting is the typecasting of a child object to a parent object. Upcasting can be done implicitly.
Upcasting gives us the
Flexibility to access the parent class members but it is not possible to access all the child class members
using this feature.
Instead of all the members, we can access some specified members of the child class. For instance, we
can access the overridden
Methods.
Ex-
7) Write a program to calculate area of 3 different shape using Compile time Polymorphism.
Class Area{
Public void areaOfShape( double base,double height ) {
a.areaOfShape(2,4);
a.areaOfShape(5);
a.areaOfShape(2,4,5);