SlideShare a Scribd company logo
Inheritance & Polymorphism
(In JAVA)
-KARTIK KAPGATE
Inheritance
Defn.- Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object.
It is an important part of OOPs (Object Oriented programming system).
Important terminology:
● Class
● Super Class:
● Sub Class
CLASS
● Defn. - A class is a group of objects which have common properties. It is a template or blueprint from which
objects are created.
Super-Class/Parent Class
● Super Class: The class whose features are inherited is known as super class(or a base class or a parent class).
Child Class/Subclass
● Sub Class: The class that inherits the other class is known as subclass(or a derived class, extended class, or
child class). The subclass can add its own fields and methods in addition to the superclass fields and methods
Types of Inheritance
♦ Single Inheritance
♦Multiple Inheritance
♦Multilevel Inheritance
♦Hierarchical Inheritance
♦Hybrid Inheritance
Single Inheritance
Defn. - When a class extends another one class only then we call it a single inheritance.
♦Class B extends only one class which is A. Here A is a parent class of B and B would be a child class of A.
Code Snippet -
Single Inheritance
Multiple Inheritance(Through Interfaces)
Defn.- In Multiple inheritance ,one class can have more than one superclass and inherit features from all parent classes.
♦Java does not support multiple inheritance with classes. In java, we can achieve multiple inheritance only through
Interfaces.
Code Snippet -
Multilevel Inheritance
Defn. - One can inherit from a derived class, thereby making this derived class the base class for the new class.
A is Superclass to B => B is child of A.
B is Superclass to C => C is child of B and Grandchild of A,
Code Snippet-
Hierarchical Inheritance
Defn. - One class serves as a superclass (base class) for more than one subclass.
♦The class A serves as a base class for the derived class B,C and D.
Code Snippet-
Hybrid Inheritance (Through Interfaces)
Defn. - It is a mix of two or more of the above types of inheritance.
A => B,C (Hierarchical Inheritance)
B,C => D (Multiple Inheritance)
Code Snippet -
Important Points
● Default superclass: Except Object class, which has no superclass, every class has one and only one direct
superclass (single inheritance). In the absence of any other explicit superclass, every class is implicitly a
subclass of Object class.
● Superclass can only be one: A superclass can have any number of subclasses. But a subclass can have only
one superclass. This is because Java does not support multiple inheritance with classes. Although with
interfaces, multiple inheritance is supported by java.
● Inheriting Constructors: A subclass inherits all the members (fields, methods, and nested classes) from its
superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the
superclass can be invoked from the subclass.
● Private member inheritance: A subclass does not inherit the private members of its parent class. However, if
the superclass has public or protected methods(like getters and setters) for accessing its private fields, these
can also be used by the subclass.
What can be done in a Subclass
● The inherited fields can be used directly, just like any other fields.
● We can declare new fields in the subclass that are not in the superclass.
● The inherited methods can be used directly as they are.
● We can write a new instance method in the subclass that has the same signature as the one in the superclass,
thus overriding it (as in example above, toString() method is overridden).
● We can write a new static method in the subclass that has the same signature as the one in the superclass,
thus hiding it.
● We can declare new methods in the subclass that are not in the superclass.
● We can write a subclass constructor that invokes the constructor of the superclass, either implicitly or by using
the keyword super.
POLYMORPHISM (In Java)
Defn. - Polymorphism in Java is a concept by which we can perform a single action in different ways.
1. ♦ In Java polymorphism is mainly divided into two types:
a. Compile time Polymorphism
i. Method Overloading
1. By Changing number of Arguments
2. By Changing Data types of Arguments
ii. Operator Overloading ( ‘+’ Operator )
b. Runtime Polymorphism
i. Method Overriding
Compile time Polymorphism
Defn. - Polymorphism that is resolved during compiler time is known as static polymorphism.
♦It is also known as static polymorphism. This type of polymorphism is achieved by function overloading or operator
overloading.
Method Overloading
Defn. -When there are multiple functions with same name but different parameters then these functions are said to be overloaded.
Functions can be overloaded by change in number of arguments or/and change in type of arguments.
1.By Changing number of Arguments 2)By Changing Data
types of Arguments
Operator Overloading
Defn. - We can make the operator (‘+’) for string class to concatenate two strings.
Runtime Polymorphism
Defn. - Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime, thats why it
is called runtime polymorphism. It is also known as Dynamic Method Dispatch.
Code Snippet-

More Related Content

What's hot

inheritance
inheritanceinheritance
inheritance
Mohit Patodia
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
Atul Sehdev
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
Tamanna Akter
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
Arnab Bhaumik
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
NithyaN19
 
Java Inheritance | Java Course
Java Inheritance | Java Course Java Inheritance | Java Course
Java Inheritance | Java Course
RAKESH P
 
Java(inheritance)
Java(inheritance)Java(inheritance)
Java(inheritance)
Pooja Bhojwani
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
M. Raihan
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Lovely Professional University
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
Kurapati Vishwak
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
VINOTH R
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Elizabeth alexander
 

What's hot (20)

Dacj 2-1 a
Dacj 2-1 aDacj 2-1 a
Dacj 2-1 a
 
inheritance
inheritanceinheritance
inheritance
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Java Inheritance | Java Course
Java Inheritance | Java Course Java Inheritance | Java Course
Java Inheritance | Java Course
 
Java(inheritance)
Java(inheritance)Java(inheritance)
Java(inheritance)
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
javainheritance
javainheritancejavainheritance
javainheritance
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 

Similar to Inheritance and Polymorphism

PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
Java session2
Java session2Java session2
Java session2
Rajeev Kumar
 
full defination of final opp.pptx
full defination of final opp.pptxfull defination of final opp.pptx
full defination of final opp.pptx
rayanbabur
 
4th_class.pdf
4th_class.pdf4th_class.pdf
4th_class.pdf
RumiHossain5
 
Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- InheritanceJava programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
Jyothishmathi Institute of Technology and Science Karimnagar
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
teach4uin
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
teach4uin
 
Java
JavaJava
Core java by amit
Core java by amitCore java by amit
Core java by amit
Thakur Amit Tomer
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
baabtra.com - No. 1 supplier of quality freshers
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Hamid Ghorbani
 
Unit 2
Unit 2Unit 2
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
Abdii Rashid
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
Arun Vasanth
 
Topic inheritance
Topic  inheritanceTopic  inheritance
Topic inheritance
Ankit Kumar
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
homeworkping9
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritance
Kalai Selvi
 
Ayan Das_25300121057.pptx
Ayan Das_25300121057.pptxAyan Das_25300121057.pptx
Ayan Das_25300121057.pptx
Ayan974999
 

Similar to Inheritance and Polymorphism (20)

PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
 
Java session2
Java session2Java session2
Java session2
 
full defination of final opp.pptx
full defination of final opp.pptxfull defination of final opp.pptx
full defination of final opp.pptx
 
4th_class.pdf
4th_class.pdf4th_class.pdf
4th_class.pdf
 
Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- InheritanceJava programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 
Java
JavaJava
Java
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
Oops
OopsOops
Oops
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Unit 2
Unit 2Unit 2
Unit 2
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
 
Topic inheritance
Topic  inheritanceTopic  inheritance
Topic inheritance
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritance
 
Ayan Das_25300121057.pptx
Ayan Das_25300121057.pptxAyan Das_25300121057.pptx
Ayan Das_25300121057.pptx
 
Unit 4
Unit 4Unit 4
Unit 4
 

Recently uploaded

Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
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
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 

Recently uploaded (20)

Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
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...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 

Inheritance and Polymorphism

  • 1. Inheritance & Polymorphism (In JAVA) -KARTIK KAPGATE
  • 2. Inheritance Defn.- Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object. It is an important part of OOPs (Object Oriented programming system). Important terminology: ● Class ● Super Class: ● Sub Class
  • 3. CLASS ● Defn. - A class is a group of objects which have common properties. It is a template or blueprint from which objects are created.
  • 4. Super-Class/Parent Class ● Super Class: The class whose features are inherited is known as super class(or a base class or a parent class).
  • 5. Child Class/Subclass ● Sub Class: The class that inherits the other class is known as subclass(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods
  • 6.
  • 7. Types of Inheritance ♦ Single Inheritance ♦Multiple Inheritance ♦Multilevel Inheritance ♦Hierarchical Inheritance ♦Hybrid Inheritance
  • 8. Single Inheritance Defn. - When a class extends another one class only then we call it a single inheritance. ♦Class B extends only one class which is A. Here A is a parent class of B and B would be a child class of A.
  • 9. Code Snippet - Single Inheritance
  • 10. Multiple Inheritance(Through Interfaces) Defn.- In Multiple inheritance ,one class can have more than one superclass and inherit features from all parent classes. ♦Java does not support multiple inheritance with classes. In java, we can achieve multiple inheritance only through Interfaces.
  • 12. Multilevel Inheritance Defn. - One can inherit from a derived class, thereby making this derived class the base class for the new class. A is Superclass to B => B is child of A. B is Superclass to C => C is child of B and Grandchild of A,
  • 14. Hierarchical Inheritance Defn. - One class serves as a superclass (base class) for more than one subclass. ♦The class A serves as a base class for the derived class B,C and D.
  • 16. Hybrid Inheritance (Through Interfaces) Defn. - It is a mix of two or more of the above types of inheritance. A => B,C (Hierarchical Inheritance) B,C => D (Multiple Inheritance)
  • 18. Important Points ● Default superclass: Except Object class, which has no superclass, every class has one and only one direct superclass (single inheritance). In the absence of any other explicit superclass, every class is implicitly a subclass of Object class. ● Superclass can only be one: A superclass can have any number of subclasses. But a subclass can have only one superclass. This is because Java does not support multiple inheritance with classes. Although with interfaces, multiple inheritance is supported by java. ● Inheriting Constructors: A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass. ● Private member inheritance: A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected methods(like getters and setters) for accessing its private fields, these can also be used by the subclass.
  • 19. What can be done in a Subclass ● The inherited fields can be used directly, just like any other fields. ● We can declare new fields in the subclass that are not in the superclass. ● The inherited methods can be used directly as they are. ● We can write a new instance method in the subclass that has the same signature as the one in the superclass, thus overriding it (as in example above, toString() method is overridden). ● We can write a new static method in the subclass that has the same signature as the one in the superclass, thus hiding it. ● We can declare new methods in the subclass that are not in the superclass. ● We can write a subclass constructor that invokes the constructor of the superclass, either implicitly or by using the keyword super.
  • 20. POLYMORPHISM (In Java) Defn. - Polymorphism in Java is a concept by which we can perform a single action in different ways. 1. ♦ In Java polymorphism is mainly divided into two types: a. Compile time Polymorphism i. Method Overloading 1. By Changing number of Arguments 2. By Changing Data types of Arguments ii. Operator Overloading ( ‘+’ Operator ) b. Runtime Polymorphism i. Method Overriding
  • 21. Compile time Polymorphism Defn. - Polymorphism that is resolved during compiler time is known as static polymorphism. ♦It is also known as static polymorphism. This type of polymorphism is achieved by function overloading or operator overloading.
  • 22. Method Overloading Defn. -When there are multiple functions with same name but different parameters then these functions are said to be overloaded. Functions can be overloaded by change in number of arguments or/and change in type of arguments. 1.By Changing number of Arguments 2)By Changing Data types of Arguments
  • 23. Operator Overloading Defn. - We can make the operator (‘+’) for string class to concatenate two strings.
  • 24. Runtime Polymorphism Defn. - Dynamic polymorphism is a process in which a call to an overridden method is resolved at runtime, thats why it is called runtime polymorphism. It is also known as Dynamic Method Dispatch.