Successfully reported this slideshow.
Your SlideShare is downloading. ×

JAVA_POLYMORPHISM.pptx

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Polymorphism
Polymorphism
Loading in …3
×

Check these out next

1 of 11 Ad

More Related Content

Similar to JAVA_POLYMORPHISM.pptx (20)

Recently uploaded (20)

Advertisement

JAVA_POLYMORPHISM.pptx

  1. 1. J AV A TE CHN OLOG IE S Centurion University Of Technology And Management
  2. 2. N ame: - Hitesh kumar N ath Regd.N O.: - 200301150005 B arnc h: - E E E POLYMORPHISM
  3. 3. TAB LE OF CON TE N TS D efinition 01 Types of Polymorphism 02 Compile Time 03 04 E xamples 05 06 Run Time Advantages
  4. 4. D efinition Polymorphism is the concept of one entity providing multiple implementations or behavior's and It is the ability of an object to make more that one form.
  5. 5. Types Of Polymorphism Polymorphism Compile Time Polymorphism Run Time polymorphism
  6. 6. Compile Time polymorphism : -  Compile-time polymorphism is also known as static polymorphism or early binding.  Compile-time polymorphism is a polymorphism that is resolved during the compilation process. Overloading of methods is called through the reference variable of a class. Compile-time polymorphism is achieved by method overloading and operator overloading. Method Overloading : -  A class having multiple methods having same name but different in parameters, it is known as Method Overloading  Method overloading increases the readability of the program.  There are two ways to overload the method in java 1. By changing number of arguments 2. By changing the data type
  7. 7. Syntax For Method Overloading : - package com.company; // by changing num of arguments public class add { static int add(int a,int b){return a+b;} static int add(int a,int b,int c){return a+b+c;} } class TestOverloading{ public static void main(String[] args){ System.out.println(add.add(15,16)); System.out.println(add.add(15,16,17)); } }  Here we have created two methods for adding two and three numbers respectively.  Used the Static methods. Output: -
  8. 8. Run Time polymorphism : -  Runtime polymorphism is a process in which a call to an overridden method is resolved at runtime rather than compile-time.  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.  Upcasting: - If the reference variable of Parent class refers to the object of Child class, it is known as upcasting. Method Overriding: -  If Child class has the same method as declared in the parent class, it is known as method overriding in Java.  Method overriding is used to provide the specific implementation of a method which is already provided by its superclass. And used for Run time polymorphism.
  9. 9. Syntax for Method Overriding: - package com.company; public class Vehicle { void run(){System.out.println("Vehicle is running"); } } class Bike2 extends Vehicle{ void run(){System.out.println("Bike is running safely"); } public static void main(String args[]){ Bike2 obj = new Bike2(); obj.run(); } } Output :-
  10. 10. Advantages Code Cleanliness Reusability and Extensibility Aligned with real world
  11. 11. THAN K YOU !

×