SlideShare a Scribd company logo
Polymorphism in java
Polymorphism:-
It is the ability of an object to take on many forms.
In java language, polymorphism is essentially considered into two versions.
• Compile time polymorphism (method overloading/ static binding )
• Runtime polymorphism (method overriding/ dynamic binding )
Compile time polymorphism (method overloading):-
This is used to write the program in such a way, that flow of control is decided in compile
time itself. It is achieved using method overloading(implicitly).
In method overloading, an object can have two or more methods with same name but with
their method parameters different. These parameters may be different on two bases:
 Parameter type: Type of method parameters can be different.
public void num(double a, double b){..}
public void num (float a, float b){..}
public void num (int a, int b){..}
 Parameter count: Functions accepting different number of parameters.
EmployeeFactory.create(String firstName, String lastName){...}
EmployeeFactory.create(Integer id, String firstName, String lastName){...}
o Both methods have same name “create” but actual method invoked will be
based on parameters passed in program.
Runtime polymorphism (method overriding):-
Feature that allows a subclass or child class to provide a specific implementation of
a method that is already provided by one of its super classes or parent classes.
public class students {
public void study(){
System.out.println(“OOP"); }
}
class Ghazanfar extends students{
public void study(){
System.out.println(“OOP,Discrete"); }
}
class Rafah extends students{
public void study(){
System.out.println(“Report writing"); }
}
Now which study() method will be called?
Depends on type of actual instance created on runtime.
public class Demo
{
public static void main(String[] args) {
students a1 = new Ghazanfar();
a1.study();
students a2 = new rafah();
a2.study();
}
}
ABSTRACTION:-
 Abstraction means hiding the implementation details and showing only the
functionality.
 Abstraction is the process of abstraction in Java is used to hide certain details and
only show the essential features of the object.
Abstract keyword
 Abstract keyword is used to declare the method or class as abstract.
 You have to place the abstract keyword before the method or class name in the
method declaration.
 An abstract method contains a method signature, but no method body.
 Instead of curly braces an abstract method will have a semi colon ( ; ) at the end.
Abstract Class :
A class which contains the abstract keyword in its declaration is known as abstract class.
Syntax:
abstract class <class-name>{}
 An abstract class is something which is incomplete and you cannot create instance of
abstract class.
 If you want to use it you need to make it complete or concrete by extending it.
 A class is called concrete if it does not contain any abstract method and implements
all abstract method inherited from abstract class or interface it has implemented or
extended.
Abstract Methods:
 If we want a class to contain a particular method but we want the actual
implementation of that method to be determined by child classes, we can declare
the method in the parent class as abstract.
 Abstract methods do not have body, they just have prototype(method signature).
 Abstract methods must be implemented in the child class (if the class is not
abstract) otherwise program will throw compilation error
Syntax:
abstract return type method name ();
 An abstract method in Java doesn't have body, it’s just a declaration. In order to
use abstract method you need to override that method in Subclass.
 A method that is declare as abstract and does not have implementation is known
as abstract method.
If you define abstract method than class must be abstract.
package program;
//abstract class
abstract class Sum{
//abstract methods
public abstract int SumOfTwo(int n1, int n2);
public abstract int SumOfThree(int n1, int n2, int n3);
//Regular method
public void disp(){ System.out.println("Method of class Sum");
} }
class AbstractDemo extends Sum{
public int SumOfTwo(int num1, int num2){
return num1+num2;
}
public int SumOfThree(int num1, int num2, int num3){
return num1+num2+num3;
}
public static void main(String args[]){
AbstractDemo obj = new AbstractDemo();
System.out.println(obj.SumOfTwo(3, 7));
System.out.println(obj.SumOfThree(4, 3, 19));
obj.disp();
} }
package presentation;
//Interface
interface Multiply{
//abstract methods
public abstract int multiplyTwo(int n1, int n2);
int multiplyThree(int n1, int n2, int n3);
}
class AbstractDemo2 implements Multiply{
public int multiplyTwo(int num1, int num2){
return num1*num2; }
public int multiplyThree(int num1, int num2, int num3){
return num1*num2*num3; }
public static void main(String args[]){
AbstractDemo2 obj = new AbstractDemo2();
System.out.println(obj.multiplyTwo(3, 7));
System.out.println(obj.multiplyThree(1, 9, 0)); } }
Polymorphism presentation in java

More Related Content

What's hot

Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Iqra khalil
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
sivasundari6
 
Method overriding
Method overridingMethod overriding
Method overriding
Azaz Maverick
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
Shraddha
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Paumil Patel
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
MustafaIbrahimy
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
Boopathi K
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
Home
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
Sujan Mia
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
Amit Soni (CTFL)
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
Shreyans Pathak
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
Nivegeetha
 

What's hot (20)

OOP java
OOP javaOOP java
OOP java
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 
Method overriding
Method overridingMethod overriding
Method overriding
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
 

Viewers also liked

Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overriding
JavaTportal
 
polymorphism
polymorphism polymorphism
polymorphism
Imtiaz Hussain
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Ahmed Za'anin
 
Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
karthikenlume
 
Oop Constructor Destructors Constructor Overloading lecture 2
Oop Constructor  Destructors Constructor Overloading lecture 2Oop Constructor  Destructors Constructor Overloading lecture 2
Oop Constructor Destructors Constructor Overloading lecture 2
Abbas Ajmal
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
M. Raihan
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in javasawarkar17
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
Haris Bin Zahid
 
Java Collections API
Java Collections APIJava Collections API
Java Collections API
Alex Miller
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Pratik Soares
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
Exception Handling
Exception HandlingException Handling
Exception Handling
Reddhi Basu
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
JavabynataraJ
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
Exception handling
Exception handlingException handling
Exception handling
Abhishek Pachisia
 

Viewers also liked (20)

Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overriding
 
polymorphism
polymorphism polymorphism
polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
 
Swt vs swing
Swt vs swingSwt vs swing
Swt vs swing
 
Oop Constructor Destructors Constructor Overloading lecture 2
Oop Constructor  Destructors Constructor Overloading lecture 2Oop Constructor  Destructors Constructor Overloading lecture 2
Oop Constructor Destructors Constructor Overloading lecture 2
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in java
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
Java Collections API
Java Collections APIJava Collections API
Java Collections API
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
Java awt
Java awtJava awt
Java awt
 
Exception handling
Exception handlingException handling
Exception handling
 

Similar to Polymorphism presentation in java

Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdf
Kp Sharma
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
SURBHI SAROHA
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
SakkaravarthiS1
 
Application package
Application packageApplication package
Application packageJAYAARC
 
Oop in kotlin
Oop in kotlinOop in kotlin
Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
Jamsher bhanbhro
 
Java notes
Java notesJava notes
Java notes
Upasana Talukdar
 
Lecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentationLecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentation
bhargavi804095
 
Lecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaionLecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaion
bhargavi804095
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
Abid Kohistani
 
Unit 4 notes.pdf
Unit 4 notes.pdfUnit 4 notes.pdf
Unit 4 notes.pdf
Revathiparamanathan
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Akhil Mittal
 
Inheritance
InheritanceInheritance
Inheritance
Mavoori Soshmitha
 
Java basics
Java basicsJava basics
Java basics
Shivanshu Purwar
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interface
manish kumar
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
ssuser7f90ae
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
Gaurav Mehta
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
Suresh Mohta
 

Similar to Polymorphism presentation in java (20)

Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdf
 
Java Unit 2(part 3)
Java Unit 2(part 3)Java Unit 2(part 3)
Java Unit 2(part 3)
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
 
Java 06
Java 06Java 06
Java 06
 
Application package
Application packageApplication package
Application package
 
Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
 
Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
 
Java notes
Java notesJava notes
Java notes
 
Lecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentationLecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentation
 
Lecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaionLecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaion
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
 
Unit 4 notes.pdf
Unit 4 notes.pdfUnit 4 notes.pdf
Unit 4 notes.pdf
 
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
Diving in OOP (Day 4): Polymorphism and Inheritance (All About Abstract Class...
 
Inheritance
InheritanceInheritance
Inheritance
 
Java basics
Java basicsJava basics
Java basics
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interface
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 

Recently uploaded

ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 

Recently uploaded (20)

ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 

Polymorphism presentation in java

  • 2. Polymorphism:- It is the ability of an object to take on many forms. In java language, polymorphism is essentially considered into two versions. • Compile time polymorphism (method overloading/ static binding ) • Runtime polymorphism (method overriding/ dynamic binding )
  • 3. Compile time polymorphism (method overloading):- This is used to write the program in such a way, that flow of control is decided in compile time itself. It is achieved using method overloading(implicitly). In method overloading, an object can have two or more methods with same name but with their method parameters different. These parameters may be different on two bases:  Parameter type: Type of method parameters can be different. public void num(double a, double b){..} public void num (float a, float b){..} public void num (int a, int b){..}  Parameter count: Functions accepting different number of parameters. EmployeeFactory.create(String firstName, String lastName){...} EmployeeFactory.create(Integer id, String firstName, String lastName){...} o Both methods have same name “create” but actual method invoked will be based on parameters passed in program.
  • 4. Runtime polymorphism (method overriding):- Feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super classes or parent classes. public class students { public void study(){ System.out.println(“OOP"); } } class Ghazanfar extends students{ public void study(){ System.out.println(“OOP,Discrete"); } } class Rafah extends students{ public void study(){ System.out.println(“Report writing"); } } Now which study() method will be called?
  • 5. Depends on type of actual instance created on runtime. public class Demo { public static void main(String[] args) { students a1 = new Ghazanfar(); a1.study(); students a2 = new rafah(); a2.study(); } }
  • 6. ABSTRACTION:-  Abstraction means hiding the implementation details and showing only the functionality.  Abstraction is the process of abstraction in Java is used to hide certain details and only show the essential features of the object. Abstract keyword  Abstract keyword is used to declare the method or class as abstract.  You have to place the abstract keyword before the method or class name in the method declaration.  An abstract method contains a method signature, but no method body.  Instead of curly braces an abstract method will have a semi colon ( ; ) at the end.
  • 7. Abstract Class : A class which contains the abstract keyword in its declaration is known as abstract class. Syntax: abstract class <class-name>{}  An abstract class is something which is incomplete and you cannot create instance of abstract class.  If you want to use it you need to make it complete or concrete by extending it.  A class is called concrete if it does not contain any abstract method and implements all abstract method inherited from abstract class or interface it has implemented or extended.
  • 8. Abstract Methods:  If we want a class to contain a particular method but we want the actual implementation of that method to be determined by child classes, we can declare the method in the parent class as abstract.  Abstract methods do not have body, they just have prototype(method signature).  Abstract methods must be implemented in the child class (if the class is not abstract) otherwise program will throw compilation error Syntax: abstract return type method name ();  An abstract method in Java doesn't have body, it’s just a declaration. In order to use abstract method you need to override that method in Subclass.  A method that is declare as abstract and does not have implementation is known as abstract method. If you define abstract method than class must be abstract.
  • 9. package program; //abstract class abstract class Sum{ //abstract methods public abstract int SumOfTwo(int n1, int n2); public abstract int SumOfThree(int n1, int n2, int n3); //Regular method public void disp(){ System.out.println("Method of class Sum"); } } class AbstractDemo extends Sum{ public int SumOfTwo(int num1, int num2){ return num1+num2; } public int SumOfThree(int num1, int num2, int num3){ return num1+num2+num3; } public static void main(String args[]){ AbstractDemo obj = new AbstractDemo(); System.out.println(obj.SumOfTwo(3, 7)); System.out.println(obj.SumOfThree(4, 3, 19)); obj.disp(); } }
  • 10. package presentation; //Interface interface Multiply{ //abstract methods public abstract int multiplyTwo(int n1, int n2); int multiplyThree(int n1, int n2, int n3); } class AbstractDemo2 implements Multiply{ public int multiplyTwo(int num1, int num2){ return num1*num2; } public int multiplyThree(int num1, int num2, int num3){ return num1*num2*num3; } public static void main(String args[]){ AbstractDemo2 obj = new AbstractDemo2(); System.out.println(obj.multiplyTwo(3, 7)); System.out.println(obj.multiplyThree(1, 9, 0)); } }