SlideShare a Scribd company logo
1 of 12
IS-A vs HAS-A Relationship
• Is-A and Has-A Relationship shows how classes or
objects are related to each in a Object oriented
design.
• Is-A relationship is based on inheritance and
interface implementation. ‘IS-A’ is way of saying
“this thing is a type of that thing” .It shows whether
a class should be inherited by other class or not.
House IS-A building, dog IS-A animal etc.
• HAS-A relationship is based on class rather than
inheritance. It shows whether a class should contain
object of other class or not.
e.g. Building HAS-A bathroom
• Polymorphism is basically the ability of an object to
take many form. ‘Any object which passes more
than one IS-A test is considered as polymorphic’.
• The java the concept of polymorphism is
supported in terms of :
Method overriding
Method overloading
Polymorphic references
Polymorphic arguments
and parameters
Polymorphic references and Array
• The most common use of polymorphism is that reference of
superclass can be used to refer objects of subclass.
• In polymorphic array reference of superclass can refer any
object of subclasses:
• public class Test {
• public static void main(String[] args)
• {
• Animal[] a = new Animal[4];
• a[0] = new Cat();
• a[1] = new Dog();
• a[2]= new Duck();
• a[3] = new Snake();
• for(int i=0; i<a.length; i++)
• {
• a[i].sound();}
Polymorphic arguments and Parameters
• Polymorphic Parameter:
Polymorphic parameters are nothing but the parameter of type
“superclass”.
e.g. If we have a method which contain polymorphic parameters then in
arguments we can pass objects of any subclass type.
• Polymorphic Arguments:
Polymorphic arguments are the arguments of type “subclass”.
• public void go(Animal a)
• {
• a.sound();
• } // in class Animal
• public static void main(String[] args)
• {
• Animal a = new Animal();
• Cat c = new Cat();
• Dog d = new Dog();
• a.go(d);
• }
Data Abstraction and Abstract Class
• Abstraction is a design concept on which we only
declare functionality but doesn't define it because
we don't know about them at design point.
• Abstract Keyword :
This is a special keyword which is used as a non-
access modifiers with classes and methods.
• Abstract Keyword with class:
If ‘abstract’ keyword is used with a class, then no
one can instantiate that class and these classes are
known as ‘abstract classes’.
• Abstract Keyword with method:
If ‘abstract’ keyword is used with method, then it
must be overridden in first concrete class????
Abstract Class Vs Concrete Class
• The classes which cannot be instantiated are
known as Abstract class.
• Concrete class are those classes which can be
intantiated
Abstract Methods and it’s properties
• The abstract Method is that method which
doesn’t contains any body and must be
overridden in first concrete class.
• Properties:
Abstract method should always use the keyword
‘abstract’ and in declaration it must be without
body.
The class of abstract method must be an abstract
class. Abstract method cannot be declare in a
concrete class.
The abstract method must be overridden by first
concrete class which extends the abstract class.
Class-Object
• The class Object is mother of all classes in java.
• Any class which doesn’t extends any other class,
implicitly extends class Object.
• Hence every class in java which extends other
class is polymorphic, i.e. every class in java “IS-A
type of Object”.
e.g.
Public class Test{}
Means
Public class Test extends Object{}
Important Method of Class - Object
• equals() method:
This method checks the equality of two objects, whether
they are equal or not
Animal a = new Cat();
Animal b = new Dog();  a.equals(b);
• getClass() method:
This method returns the real class name of it’s
corresponding object.
e.g. b.getClass();
• hashCode()
This method finds the hashCode of a object
e.g. b.hashCode();
• toString():
This method returns the string representation of an object
Class of reference variable
• During the call of method of an object, the
compiler searches the method in class of
reference variable and not in the actual class of
the object.
• public static void main(String[] args)
• {
• Object o = new Animal();
• o.eat();
• }
Limitation of Multiple inheritance
• Multiple Inheritance is the mechanism of
extending more than one superclass.
• Java doesn’t supports multiple inheritance
due to it’s limitation in “deadly diamond of
death”
Solution of DDoD in java - Interfaces
• In java the alternative of multiple inheritance is
INTERFACES
• INTERFACES are nothing but the pure abstract
class which can be implement by any other
class along with extending other classes

More Related Content

Similar to Java Lecture5.pptx

Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxethiouniverse
 
3.Classes&Objects.pptx
3.Classes&Objects.pptx3.Classes&Objects.pptx
3.Classes&Objects.pptxPRABHUSOLOMON1
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in JavaRavi_Kant_Sahu
 
Object Oriented Programming.pptx
Object Oriented Programming.pptxObject Oriented Programming.pptx
Object Oriented Programming.pptxSAICHARANREDDYN
 
Ruby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for rubyRuby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for rubyTushar Pal
 
encapsulation and abstraction
encapsulation and abstractionencapsulation and abstraction
encapsulation and abstractionALIZAPARVIN
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Christopher Haupt
 
Introduction to OOP with java
Introduction to OOP with javaIntroduction to OOP with java
Introduction to OOP with javaSujit Kumar
 
Java As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & AppletsJava As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & AppletsHelen SagayaRaj
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritanceteach4uin
 

Similar to Java Lecture5.pptx (20)

Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptx
 
3.Classes&Objects.pptx
3.Classes&Objects.pptx3.Classes&Objects.pptx
3.Classes&Objects.pptx
 
Object concepts
Object conceptsObject concepts
Object concepts
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
 
Unit3 part2-inheritance
Unit3 part2-inheritanceUnit3 part2-inheritance
Unit3 part2-inheritance
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
Java
JavaJava
Java
 
OOPS Characteristics
OOPS CharacteristicsOOPS Characteristics
OOPS Characteristics
 
Object Oriented Programming.pptx
Object Oriented Programming.pptxObject Oriented Programming.pptx
Object Oriented Programming.pptx
 
Ruby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for rubyRuby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for ruby
 
Ch5 inheritance
Ch5 inheritanceCh5 inheritance
Ch5 inheritance
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
encapsulation and abstraction
encapsulation and abstractionencapsulation and abstraction
encapsulation and abstraction
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)
 
Introduction to OOP with java
Introduction to OOP with javaIntroduction to OOP with java
Introduction to OOP with java
 
Java As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & AppletsJava As an OOP Language,Exception Handling & Applets
Java As an OOP Language,Exception Handling & Applets
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Java defining classes
Java defining classes Java defining classes
Java defining classes
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 

Recently uploaded

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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
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
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 

Recently uploaded (20)

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
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
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
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Java Lecture5.pptx

  • 1. IS-A vs HAS-A Relationship • Is-A and Has-A Relationship shows how classes or objects are related to each in a Object oriented design. • Is-A relationship is based on inheritance and interface implementation. ‘IS-A’ is way of saying “this thing is a type of that thing” .It shows whether a class should be inherited by other class or not. House IS-A building, dog IS-A animal etc. • HAS-A relationship is based on class rather than inheritance. It shows whether a class should contain object of other class or not. e.g. Building HAS-A bathroom
  • 2. • Polymorphism is basically the ability of an object to take many form. ‘Any object which passes more than one IS-A test is considered as polymorphic’. • The java the concept of polymorphism is supported in terms of : Method overriding Method overloading Polymorphic references Polymorphic arguments and parameters
  • 3. Polymorphic references and Array • The most common use of polymorphism is that reference of superclass can be used to refer objects of subclass. • In polymorphic array reference of superclass can refer any object of subclasses: • public class Test { • public static void main(String[] args) • { • Animal[] a = new Animal[4]; • a[0] = new Cat(); • a[1] = new Dog(); • a[2]= new Duck(); • a[3] = new Snake(); • for(int i=0; i<a.length; i++) • { • a[i].sound();}
  • 4. Polymorphic arguments and Parameters • Polymorphic Parameter: Polymorphic parameters are nothing but the parameter of type “superclass”. e.g. If we have a method which contain polymorphic parameters then in arguments we can pass objects of any subclass type. • Polymorphic Arguments: Polymorphic arguments are the arguments of type “subclass”. • public void go(Animal a) • { • a.sound(); • } // in class Animal • public static void main(String[] args) • { • Animal a = new Animal(); • Cat c = new Cat(); • Dog d = new Dog(); • a.go(d); • }
  • 5. Data Abstraction and Abstract Class • Abstraction is a design concept on which we only declare functionality but doesn't define it because we don't know about them at design point. • Abstract Keyword : This is a special keyword which is used as a non- access modifiers with classes and methods. • Abstract Keyword with class: If ‘abstract’ keyword is used with a class, then no one can instantiate that class and these classes are known as ‘abstract classes’. • Abstract Keyword with method: If ‘abstract’ keyword is used with method, then it must be overridden in first concrete class????
  • 6. Abstract Class Vs Concrete Class • The classes which cannot be instantiated are known as Abstract class. • Concrete class are those classes which can be intantiated
  • 7. Abstract Methods and it’s properties • The abstract Method is that method which doesn’t contains any body and must be overridden in first concrete class. • Properties: Abstract method should always use the keyword ‘abstract’ and in declaration it must be without body. The class of abstract method must be an abstract class. Abstract method cannot be declare in a concrete class. The abstract method must be overridden by first concrete class which extends the abstract class.
  • 8. Class-Object • The class Object is mother of all classes in java. • Any class which doesn’t extends any other class, implicitly extends class Object. • Hence every class in java which extends other class is polymorphic, i.e. every class in java “IS-A type of Object”. e.g. Public class Test{} Means Public class Test extends Object{}
  • 9. Important Method of Class - Object • equals() method: This method checks the equality of two objects, whether they are equal or not Animal a = new Cat(); Animal b = new Dog();  a.equals(b); • getClass() method: This method returns the real class name of it’s corresponding object. e.g. b.getClass(); • hashCode() This method finds the hashCode of a object e.g. b.hashCode(); • toString(): This method returns the string representation of an object
  • 10. Class of reference variable • During the call of method of an object, the compiler searches the method in class of reference variable and not in the actual class of the object. • public static void main(String[] args) • { • Object o = new Animal(); • o.eat(); • }
  • 11. Limitation of Multiple inheritance • Multiple Inheritance is the mechanism of extending more than one superclass. • Java doesn’t supports multiple inheritance due to it’s limitation in “deadly diamond of death”
  • 12. Solution of DDoD in java - Interfaces • In java the alternative of multiple inheritance is INTERFACES • INTERFACES are nothing but the pure abstract class which can be implement by any other class along with extending other classes