SlideShare a Scribd company logo
1 of 25
Java/J2ee Programming Training
Polymorphism
Page 2Classification: Restricted
Agenda
• Poly- many
• morphism –forms.
• An entity existing in more than one form.
• methods,
• objects.
Page 3Classification: Restricted
Polymorphism
• polymorphism
• static polymorphism
• entity exists in more than one form physically
• implemented in java using method overloading concept
• dynamic polymorphism
• type of the object is decided at run time
• implemented using
• method overriding
• polymorphic arguments, return types
• abstract classes
• interfaces.
Page 4Classification: Restricted
Polymorphism
• Method overloading
• method physically exists in more than one form.
• method with the same name but different signature list.
• signature of the method should differ atleast
• number of arguments
• data type of arguments
• order of arguments.
• which function to invoke is decided at compile time( early binding )
Page 5Classification: Restricted
Static Polymorphism
public void add( int a, int b)
Differs in Number of arguments
public void add( int a , int b)
public void add( int a, int b, int c )
Differs Datatype of arguments
public void add ( int a , int b)
public void add( int a, float b)
Differs in Order of arguments
public void add( int a, float b)
public void add( float a, int b)
Page 6Classification: Restricted
public void add( int a, int b)
{
System.out.println( “sum = “+(a + b) );
}
public void add( int a, int b, int c)
{
System.out.println( “sum = “+(a + b +c ) );
}
public void add( int a, float b)
{
System.out.println( “sum = “+(a + b) );
}
public void add( float a, int b)
{
System.out.println( “sum = “+(a + b) );
}
public static void main(String args[] ) {
int a = 10; int b = 20;
add( a, b);
}
Page 7Classification: Restricted
public void add( int a, int b)
{
System.out.println( “sum = “+(a + b) );
}
public void add( int a, int b, int c)
{
System.out.println( “sum = “+(a + b +c ) );
}
public static void main(String args[] ) {
int a = 10; int b = 20; int c = 30
add( a, b, c );
}
number of
argument
s varies
Page 8Classification: Restricted
public void add( int a, int b, int c)
{
System.out.println( “sum = “+(a + b +c ) );
}
public void add( int a, int b)
{
System.out.println( “sum = “+(a + b) );
}
public void add( int a, float b)
{
System.out.println( “sum = “+(a + b) );
}
public static void main(String args[] ) {
int a = 10; float b = 30.5;
add( a, b);
}
datatype of
arguments varies
Page 9Classification: Restricted
public void add( int a, int b)
{
System.out.println( “sum = “+(a + b) );
}
public void add( int a, float b)
{
System.out.println( “sum = “+(a + b) );
}
public void add( float a, int b)
{
System.out.println( “sum = “+(a + b) );
}
public static void main(String args[] ) {
float a = 10; int b = 30.5;
add( a, b);
}
order of arguments
varies
Page 10Classification: Restricted
Polymorphism
• public void add( int a , int b )
• public int add( int a , int b)
• return type is not taken into consideration
• public void add( int a , int b )
• private int add( int a , int b)
• access specifier is not taken into consideration
Page 11Classification: Restricted
DynamicPolymorphism
• Method overriding
• functions have the same signature but different logic
• methods inherited from the base class are overridden in child class.
• access specifier can be more friendly.
• supports late binding principle
public class Employee
{
private String uname,email;
public void register()
{
System.out.println(“Enter uname”);
uname = sc.next();
System.out.println(“Enter email”);
email =sc.next();
}
}
public class Employee2 extends Employee
{
private String biometrics;
public void register()
{
super.register();
System.out.println(“scan finger”);
biometrics =“finger pattern”;
}
}
Employee
String uname
String email
+ void register()
Employee2
String uname
String email
+ void register()
public class Employee
{
private String uname,email;
public void register()
{
System.out.println(“Enter uname”);
uname = sc.next();
System.out.println(“Enter email”);
email =sc.next();
}
}
public class Employee2 extends Employee
{
private String captcha;
public void register()
{
super.register();
System.out.println(“Enter Image”);
captcha=“ABc123”;
}
}
Employee
String uname
String email
+ void register()
Employee2
String uname
String email
+ void register()
Shape
String name;
int dim1;
int dim2;
Rectangle
String name;
int dim1;
int dim2;
+ void details()
+void area();
Triangle
String name;
int dim1;
int dim2;
+void details();
+void area();
+ void details()
{
S.o.p (name +” “ + dim1 + “ “ +dim2 );
}
+void area()
{
S.o.p (“area = “ + dim1 * dim2);
}
+ void details()
{
S.o.p (name +” “ + dim1 + “ “ +dim2 );
}
+void area()
{
S.o.p (“area = “ +0.5f * dim1 * dim2);
}
+ void details()
{
S.o.p (name +” “ + dim1 + “ “ +dim2 );
}
+void area()
{
S.o.p (“area = “ +0.5f * dim1 * dim2);
}
+ void details()
{
S.o.p (name +” “ + dim1 + “ “ +dim2 );
}
+ abstract void area();
Animal
String name;
int height;
int weight;
Cat
String name;
int height;
int weight;
+ void details()
+void makeNoise();
Dog
String name;
int height;
int weight;
+void details();
+void makeNoise();
+ void details()
{
S.o.p (name +” “ + height+ “ “ +weight);
}
+void makeNoise()
{
S.o.p (“cat meow meow“);
}
+ void details()
{
S.o.p (name +” “ + height+ “ “ +weight);
}
+void makeNoise()
{
S.o.p(“Dog’s bow”);
}
+ void details()
{
S.o.p (name +” “ + height+ “ “ +weight);
}
+void makeNoise()
{
S.o.p (“whattype of noise????”);
}
+ void details()
{
S.o.p (name +” “ + height+ “ “ +weight);
}
+ abstract void makeNoise();
Animal
String name;
int height;
int weight;
Cat
String name;
int height;
int weight;
+ void details()
+void area();
Dog
String name;
int height;
int weight;
+void details();
+void area();
+ void details()
{
S.o.p (name +” “ + height+ “ “ +weight);
}
+void makeNoise()
{
S.o.p (“cat meow meow“);
}
+ void details()
{
S.o.p (name +” “ + height+ “ “ +weight);
}
+void makeNoise()
{
S.o.p(“Dog’s bow”);
}
+ void details()
{
S.o.p (name +” “ + height+ “ “ +weight);
}
+void area()
{
S.o.p (“whattype of noise????”);
}
+ void details()
{
S.o.p (name +” “ + height+ “ “ +weight);
}
+ abstract void makeNoise();
Animal is an abstract
class
Cat is
concrete
Dog is
concrete
Concrete
method
Concrete
method
Page 17Classification: Restricted
Abstract
• Animal is an abstract class.
• We can create an object of abstract class.
• Animal animal = new Animal();
• Objects have well defined behavior.
• Object has well defined behavior, makeNoise() method in animal
class doesn’t have behavior.
• jvm doesn’t know about the object behavior and prohibits
creating the object.
Page 18Classification: Restricted
Abstract Classes
• Animal animal = new Animal();
What type of
Animal…dog..or
cat…??
do animal make same
type of Noise????
Then let us not
create the object
of Animal…make
Animal class
abstract.
Page 19Classification: Restricted
a.makeNoise()
Dog
String name;
int height;
int weight;
String xxx;
+void makeNoise()
{
S.o.p(“Dog’s
bow”);
}
Cat
String name;
int height;
int weight;
String yyy;
+void makeNoise()
{
S.o.p(“cats
meow”);
}
Animal
String name;
int height;
int weight;
+void
makeNoise()Animal a = new Dog();
a.makeNoise()
Dog
String name;
int height;
int weight;
String xxx;
+void makeNoise()
{
S.o.p(“cats meoww”);
}
Cat
String name;
int height;
int weight;
String yyy;
+void makeNoise()
{
S.o.p(“Dog’s bow”);
}
Animal
String name;
int height;
int weight;
+void makeNoise()Animal a = new Cat();
Dog
String name;
int height;
int weight;
String xxx;
+void makeNoise()
{
S.o.p(“cats meoww”);
}
Cat
String name;
int height;
int weight;
String yyy;
+void makeNoise()
{
S.o.p(“Dog’s bow”);
}
Animal
String name;
int height;
int weight;
+void makeNoise()
+void playSound( Animal a )
{
a.makeNoise();
}
Dog
String name;
int height;
int weight;
String xxx;
+void makeNoise()
{
S.o.p(“Dog meoww”);
}
Cat
String name;
int height;
int weight;
String yyy;
+void makeNoise()
{
S.o.p(“Cat meow”);
}
Animal
String name;
int height;
int weight;
+void makeNoise()
+void playSound( Animal a )
{
a.makeNoise();
}
Page 23Classification: Restricted
Interfaces
• Interfaces – prototype
• all methods declared in an interface are by default abstract
• member variables are static and final
<<Employee>>
public static final int MIN_LEAVE= 1;
public static final int MAX_LEAVE = 30;
abstract void applyLeave();
abstract void cancelLeave();
EmpFileSystem
public String filename;
public int MAX_SIZE;
+ void applyLeave()
{
//code for applyLeave
}
+ void cancelLeave()
{
}
EmpDatabaseSystem
public String dbName;
public String url
+ void applyLeave()
{
//code for applyLeave
}
+ void cancelLeave()
{
}
Page 25Classification: Restricted
Thank You

More Related Content

What's hot

C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsMohammad Shaker
 
About java
About javaAbout java
About javaJay Xu
 
2.1 Recap From Day One
2.1 Recap From Day One2.1 Recap From Day One
2.1 Recap From Day Oneretronym
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreWeb Zhao
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScriptJulie Iskander
 
Les nouveautés de C# 6
Les nouveautés de C# 6Les nouveautés de C# 6
Les nouveautés de C# 6Microsoft
 
The Ring programming language version 1.9 book - Part 84 of 210
The Ring programming language version 1.9 book - Part 84 of 210The Ring programming language version 1.9 book - Part 84 of 210
The Ring programming language version 1.9 book - Part 84 of 210Mahmoud Samir Fayed
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うbpstudy
 
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 31 of 184
The Ring programming language version 1.5.3 book - Part 31 of 184The Ring programming language version 1.5.3 book - Part 31 of 184
The Ring programming language version 1.5.3 book - Part 31 of 184Mahmoud Samir Fayed
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritanceshatha00
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectOUM SAOKOSAL
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulationShahjahan Samoon
 
Java Puzzle
Java PuzzleJava Puzzle
Java PuzzleSFilipp
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulationIntro C# Book
 

What's hot (20)

C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and Objects
 
About java
About javaAbout java
About java
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
2.1 Recap From Day One
2.1 Recap From Day One2.1 Recap From Day One
2.1 Recap From Day One
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Les nouveautés de C# 6
Les nouveautés de C# 6Les nouveautés de C# 6
Les nouveautés de C# 6
 
The Ring programming language version 1.9 book - Part 84 of 210
The Ring programming language version 1.9 book - Part 84 of 210The Ring programming language version 1.9 book - Part 84 of 210
The Ring programming language version 1.9 book - Part 84 of 210
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
 
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202
 
Object calisthenics
Object calisthenicsObject calisthenics
Object calisthenics
 
The Ring programming language version 1.5.3 book - Part 31 of 184
The Ring programming language version 1.5.3 book - Part 31 of 184The Ring programming language version 1.5.3 book - Part 31 of 184
The Ring programming language version 1.5.3 book - Part 31 of 184
 
C h 04 oop_inheritance
C h 04 oop_inheritanceC h 04 oop_inheritance
C h 04 oop_inheritance
 
Scala vs java 8
Scala vs java 8Scala vs java 8
Scala vs java 8
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and Object
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
Kotlin
KotlinKotlin
Kotlin
 

Similar to Java Polymorphism Part 2

Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contdraksharao
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programsKaruppaiyaa123
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfShashikantSathe3
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Ayes Chinmay
 
What's new in C# 6 - NetPonto Porto 20160116
What's new in C# 6  - NetPonto Porto 20160116What's new in C# 6  - NetPonto Porto 20160116
What's new in C# 6 - NetPonto Porto 20160116Paulo Morgado
 
Java 8 Puzzlers [as presented at OSCON 2016]
Java 8 Puzzlers [as presented at  OSCON 2016]Java 8 Puzzlers [as presented at  OSCON 2016]
Java 8 Puzzlers [as presented at OSCON 2016]Baruch Sadogursky
 
Basic program in java
Basic program in java Basic program in java
Basic program in java Sudeep Singh
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)teach4uin
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme SwiftMovel
 
Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013yohanbeschi
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 

Similar to Java Polymorphism Part 2 (20)

Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Dotnet 18
Dotnet 18Dotnet 18
Dotnet 18
 
Java practical
Java practicalJava practical
Java practical
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
What's new in C# 6 - NetPonto Porto 20160116
What's new in C# 6  - NetPonto Porto 20160116What's new in C# 6  - NetPonto Porto 20160116
What's new in C# 6 - NetPonto Porto 20160116
 
Java 8 Puzzlers [as presented at OSCON 2016]
Java 8 Puzzlers [as presented at  OSCON 2016]Java 8 Puzzlers [as presented at  OSCON 2016]
Java 8 Puzzlers [as presented at OSCON 2016]
 
Java Program
Java ProgramJava Program
Java Program
 
Basic program in java
Basic program in java Basic program in java
Basic program in java
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
 
Java Language fundamental
Java Language fundamentalJava Language fundamental
Java Language fundamental
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013Building Single-Page Web Appplications in dart - Devoxx France 2013
Building Single-Page Web Appplications in dart - Devoxx France 2013
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 

More from AathikaJava

Java Webservices
Java WebservicesJava Webservices
Java WebservicesAathikaJava
 
Java Type Casting
Java Type Casting Java Type Casting
Java Type Casting AathikaJava
 
Java Servlet Lifecycle
Java Servlet LifecycleJava Servlet Lifecycle
Java Servlet LifecycleAathikaJava
 
Java Request Dispatcher
Java Request DispatcherJava Request Dispatcher
Java Request DispatcherAathikaJava
 
Java Polymorphism
Java PolymorphismJava Polymorphism
Java PolymorphismAathikaJava
 
Mapping Classes with Relational Databases
Mapping Classes with Relational DatabasesMapping Classes with Relational Databases
Mapping Classes with Relational DatabasesAathikaJava
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to JavaAathikaJava
 
Java Encapsulation and Inheritance
Java Encapsulation and Inheritance Java Encapsulation and Inheritance
Java Encapsulation and Inheritance AathikaJava
 
Hibernate basics
Hibernate basicsHibernate basics
Hibernate basicsAathikaJava
 

More from AathikaJava (17)

Java While Loop
Java While LoopJava While Loop
Java While Loop
 
Java Webservices
Java WebservicesJava Webservices
Java Webservices
 
Java Type Casting
Java Type Casting Java Type Casting
Java Type Casting
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Java Session
Java SessionJava Session
Java Session
 
Java Servlet Lifecycle
Java Servlet LifecycleJava Servlet Lifecycle
Java Servlet Lifecycle
 
Java Rest
Java Rest Java Rest
Java Rest
 
Java Request Dispatcher
Java Request DispatcherJava Request Dispatcher
Java Request Dispatcher
 
Java MVC
Java MVCJava MVC
Java MVC
 
Java Polymorphism
Java PolymorphismJava Polymorphism
Java Polymorphism
 
Java Spring
Java SpringJava Spring
Java Spring
 
Mapping Classes with Relational Databases
Mapping Classes with Relational DatabasesMapping Classes with Relational Databases
Mapping Classes with Relational Databases
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Java Encapsulation and Inheritance
Java Encapsulation and Inheritance Java Encapsulation and Inheritance
Java Encapsulation and Inheritance
 
Hibernate basics
Hibernate basicsHibernate basics
Hibernate basics
 
Java Filters
Java FiltersJava Filters
Java Filters
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 

Recently uploaded

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

Java Polymorphism Part 2

  • 2. Page 2Classification: Restricted Agenda • Poly- many • morphism –forms. • An entity existing in more than one form. • methods, • objects.
  • 3. Page 3Classification: Restricted Polymorphism • polymorphism • static polymorphism • entity exists in more than one form physically • implemented in java using method overloading concept • dynamic polymorphism • type of the object is decided at run time • implemented using • method overriding • polymorphic arguments, return types • abstract classes • interfaces.
  • 4. Page 4Classification: Restricted Polymorphism • Method overloading • method physically exists in more than one form. • method with the same name but different signature list. • signature of the method should differ atleast • number of arguments • data type of arguments • order of arguments. • which function to invoke is decided at compile time( early binding )
  • 5. Page 5Classification: Restricted Static Polymorphism public void add( int a, int b) Differs in Number of arguments public void add( int a , int b) public void add( int a, int b, int c ) Differs Datatype of arguments public void add ( int a , int b) public void add( int a, float b) Differs in Order of arguments public void add( int a, float b) public void add( float a, int b)
  • 6. Page 6Classification: Restricted public void add( int a, int b) { System.out.println( “sum = “+(a + b) ); } public void add( int a, int b, int c) { System.out.println( “sum = “+(a + b +c ) ); } public void add( int a, float b) { System.out.println( “sum = “+(a + b) ); } public void add( float a, int b) { System.out.println( “sum = “+(a + b) ); } public static void main(String args[] ) { int a = 10; int b = 20; add( a, b); }
  • 7. Page 7Classification: Restricted public void add( int a, int b) { System.out.println( “sum = “+(a + b) ); } public void add( int a, int b, int c) { System.out.println( “sum = “+(a + b +c ) ); } public static void main(String args[] ) { int a = 10; int b = 20; int c = 30 add( a, b, c ); } number of argument s varies
  • 8. Page 8Classification: Restricted public void add( int a, int b, int c) { System.out.println( “sum = “+(a + b +c ) ); } public void add( int a, int b) { System.out.println( “sum = “+(a + b) ); } public void add( int a, float b) { System.out.println( “sum = “+(a + b) ); } public static void main(String args[] ) { int a = 10; float b = 30.5; add( a, b); } datatype of arguments varies
  • 9. Page 9Classification: Restricted public void add( int a, int b) { System.out.println( “sum = “+(a + b) ); } public void add( int a, float b) { System.out.println( “sum = “+(a + b) ); } public void add( float a, int b) { System.out.println( “sum = “+(a + b) ); } public static void main(String args[] ) { float a = 10; int b = 30.5; add( a, b); } order of arguments varies
  • 10. Page 10Classification: Restricted Polymorphism • public void add( int a , int b ) • public int add( int a , int b) • return type is not taken into consideration • public void add( int a , int b ) • private int add( int a , int b) • access specifier is not taken into consideration
  • 11. Page 11Classification: Restricted DynamicPolymorphism • Method overriding • functions have the same signature but different logic • methods inherited from the base class are overridden in child class. • access specifier can be more friendly. • supports late binding principle
  • 12. public class Employee { private String uname,email; public void register() { System.out.println(“Enter uname”); uname = sc.next(); System.out.println(“Enter email”); email =sc.next(); } } public class Employee2 extends Employee { private String biometrics; public void register() { super.register(); System.out.println(“scan finger”); biometrics =“finger pattern”; } } Employee String uname String email + void register() Employee2 String uname String email + void register()
  • 13. public class Employee { private String uname,email; public void register() { System.out.println(“Enter uname”); uname = sc.next(); System.out.println(“Enter email”); email =sc.next(); } } public class Employee2 extends Employee { private String captcha; public void register() { super.register(); System.out.println(“Enter Image”); captcha=“ABc123”; } } Employee String uname String email + void register() Employee2 String uname String email + void register()
  • 14. Shape String name; int dim1; int dim2; Rectangle String name; int dim1; int dim2; + void details() +void area(); Triangle String name; int dim1; int dim2; +void details(); +void area(); + void details() { S.o.p (name +” “ + dim1 + “ “ +dim2 ); } +void area() { S.o.p (“area = “ + dim1 * dim2); } + void details() { S.o.p (name +” “ + dim1 + “ “ +dim2 ); } +void area() { S.o.p (“area = “ +0.5f * dim1 * dim2); } + void details() { S.o.p (name +” “ + dim1 + “ “ +dim2 ); } +void area() { S.o.p (“area = “ +0.5f * dim1 * dim2); } + void details() { S.o.p (name +” “ + dim1 + “ “ +dim2 ); } + abstract void area();
  • 15. Animal String name; int height; int weight; Cat String name; int height; int weight; + void details() +void makeNoise(); Dog String name; int height; int weight; +void details(); +void makeNoise(); + void details() { S.o.p (name +” “ + height+ “ “ +weight); } +void makeNoise() { S.o.p (“cat meow meow“); } + void details() { S.o.p (name +” “ + height+ “ “ +weight); } +void makeNoise() { S.o.p(“Dog’s bow”); } + void details() { S.o.p (name +” “ + height+ “ “ +weight); } +void makeNoise() { S.o.p (“whattype of noise????”); } + void details() { S.o.p (name +” “ + height+ “ “ +weight); } + abstract void makeNoise();
  • 16. Animal String name; int height; int weight; Cat String name; int height; int weight; + void details() +void area(); Dog String name; int height; int weight; +void details(); +void area(); + void details() { S.o.p (name +” “ + height+ “ “ +weight); } +void makeNoise() { S.o.p (“cat meow meow“); } + void details() { S.o.p (name +” “ + height+ “ “ +weight); } +void makeNoise() { S.o.p(“Dog’s bow”); } + void details() { S.o.p (name +” “ + height+ “ “ +weight); } +void area() { S.o.p (“whattype of noise????”); } + void details() { S.o.p (name +” “ + height+ “ “ +weight); } + abstract void makeNoise(); Animal is an abstract class Cat is concrete Dog is concrete Concrete method Concrete method
  • 17. Page 17Classification: Restricted Abstract • Animal is an abstract class. • We can create an object of abstract class. • Animal animal = new Animal(); • Objects have well defined behavior. • Object has well defined behavior, makeNoise() method in animal class doesn’t have behavior. • jvm doesn’t know about the object behavior and prohibits creating the object.
  • 18. Page 18Classification: Restricted Abstract Classes • Animal animal = new Animal(); What type of Animal…dog..or cat…?? do animal make same type of Noise???? Then let us not create the object of Animal…make Animal class abstract.
  • 19. Page 19Classification: Restricted a.makeNoise() Dog String name; int height; int weight; String xxx; +void makeNoise() { S.o.p(“Dog’s bow”); } Cat String name; int height; int weight; String yyy; +void makeNoise() { S.o.p(“cats meow”); } Animal String name; int height; int weight; +void makeNoise()Animal a = new Dog();
  • 20. a.makeNoise() Dog String name; int height; int weight; String xxx; +void makeNoise() { S.o.p(“cats meoww”); } Cat String name; int height; int weight; String yyy; +void makeNoise() { S.o.p(“Dog’s bow”); } Animal String name; int height; int weight; +void makeNoise()Animal a = new Cat();
  • 21. Dog String name; int height; int weight; String xxx; +void makeNoise() { S.o.p(“cats meoww”); } Cat String name; int height; int weight; String yyy; +void makeNoise() { S.o.p(“Dog’s bow”); } Animal String name; int height; int weight; +void makeNoise() +void playSound( Animal a ) { a.makeNoise(); }
  • 22. Dog String name; int height; int weight; String xxx; +void makeNoise() { S.o.p(“Dog meoww”); } Cat String name; int height; int weight; String yyy; +void makeNoise() { S.o.p(“Cat meow”); } Animal String name; int height; int weight; +void makeNoise() +void playSound( Animal a ) { a.makeNoise(); }
  • 23. Page 23Classification: Restricted Interfaces • Interfaces – prototype • all methods declared in an interface are by default abstract • member variables are static and final
  • 24. <<Employee>> public static final int MIN_LEAVE= 1; public static final int MAX_LEAVE = 30; abstract void applyLeave(); abstract void cancelLeave(); EmpFileSystem public String filename; public int MAX_SIZE; + void applyLeave() { //code for applyLeave } + void cancelLeave() { } EmpDatabaseSystem public String dbName; public String url + void applyLeave() { //code for applyLeave } + void cancelLeave() { }