Sub:- JAVA PROGRAMMING
Guided By :-
Prof. Satyanarayan Sahu
Ujjwal Kumar (230101120300)
Chetna Sharma (230101120299)
Kamendra Kumar (230101120302)
Sonu Kumar (230101120298)
Introduction to Single Inheritance
 Single inheritance is a fundamental concept
in object-oriented programming.
 It allows a class to inherit properties and
behaviors from one parent class.
 This promotes code reusability and
establishes a clear hierarchy within the
classes.
Key Concepts
 In single inheritance, a subclass derives
from one superclass only.
 The subclass can access public and
protected members of the superclass.
 This relationship can be visualized as a tree,
where each class has one direct parent.
Syntax of Single Inheritance
 A subclass is defined using the `extends`
keyword in Java.
 The superclass can provide its methods and
fields to the subclass.
Example: `class SubClass extends SuperClass
{ }` illustrates this concept.
Advantages of Single Inheritance
 It simplifies the class structure by
eliminating multiple parent classes.
 There is less complexity in method
resolution, making code easier to
understand.
 Code reusability is enhanced, reducing
redundancy and improving maintainability.
Limitations of Single Inheritance
 Single inheritance can lead to limitations in
class functionality.
 It restricts the subclass to inherit from only
one superclass.
 This can be somewhat limiting in scenarios
where multiple behaviors are needed.
Example of Single Inheritance
 Consider a superclass called `Animal` with
a method `makeSound()`.
 A subclass called `Dog` can inherit this
method from `Animal`.
This allows `Dog` to utilize the `makeSound()`
method without redefining it.
Overriding Methods in Single Inheritance
 Subclasses can override methods from their
superclass to provide specific functionality.
 This is done by defining a method in the
subclass with the same signature.
 The ‘@Override’ annotation is commonly
used to indicate method overriding.
Access Modifiers in Single Inheritance
 The access modifier of superclass members
affects their visibility in subclasses.
 Public members are accessible from
anywhere, while protected members are
limited to the package and subclasses.
 Private members are not accessible in
subclasses, ensuring encapsulation.
Real-World Examples
 In a banking application, a `Account`
superclass can define common features.
 Subclasses like `SavingsAccount` and
`CurrentAccount` can inherit from
`Account`.
 This models real-world relationships and
allows specific implementations for each
account type.
Conclusion
 Single inheritance is a powerful tool in Java
for building organized and maintainable
systems.
 It promotes a clean hierarchy and code reuse
but comes with certain limitations.
 Understanding single inheritance is essential
for mastering Java's object-oriented features.
Java_ppt_ujjwal_kr01[1]  -  Read-Only.pptx

Java_ppt_ujjwal_kr01[1] - Read-Only.pptx

  • 1.
    Sub:- JAVA PROGRAMMING GuidedBy :- Prof. Satyanarayan Sahu Ujjwal Kumar (230101120300) Chetna Sharma (230101120299) Kamendra Kumar (230101120302) Sonu Kumar (230101120298)
  • 2.
    Introduction to SingleInheritance  Single inheritance is a fundamental concept in object-oriented programming.  It allows a class to inherit properties and behaviors from one parent class.  This promotes code reusability and establishes a clear hierarchy within the classes.
  • 3.
    Key Concepts  Insingle inheritance, a subclass derives from one superclass only.  The subclass can access public and protected members of the superclass.  This relationship can be visualized as a tree, where each class has one direct parent.
  • 4.
    Syntax of SingleInheritance  A subclass is defined using the `extends` keyword in Java.  The superclass can provide its methods and fields to the subclass. Example: `class SubClass extends SuperClass { }` illustrates this concept.
  • 5.
    Advantages of SingleInheritance  It simplifies the class structure by eliminating multiple parent classes.  There is less complexity in method resolution, making code easier to understand.  Code reusability is enhanced, reducing redundancy and improving maintainability.
  • 6.
    Limitations of SingleInheritance  Single inheritance can lead to limitations in class functionality.  It restricts the subclass to inherit from only one superclass.  This can be somewhat limiting in scenarios where multiple behaviors are needed.
  • 7.
    Example of SingleInheritance  Consider a superclass called `Animal` with a method `makeSound()`.  A subclass called `Dog` can inherit this method from `Animal`. This allows `Dog` to utilize the `makeSound()` method without redefining it.
  • 8.
    Overriding Methods inSingle Inheritance  Subclasses can override methods from their superclass to provide specific functionality.  This is done by defining a method in the subclass with the same signature.  The ‘@Override’ annotation is commonly used to indicate method overriding.
  • 9.
    Access Modifiers inSingle Inheritance  The access modifier of superclass members affects their visibility in subclasses.  Public members are accessible from anywhere, while protected members are limited to the package and subclasses.  Private members are not accessible in subclasses, ensuring encapsulation.
  • 10.
    Real-World Examples  Ina banking application, a `Account` superclass can define common features.  Subclasses like `SavingsAccount` and `CurrentAccount` can inherit from `Account`.  This models real-world relationships and allows specific implementations for each account type.
  • 11.
    Conclusion  Single inheritanceis a powerful tool in Java for building organized and maintainable systems.  It promotes a clean hierarchy and code reuse but comes with certain limitations.  Understanding single inheritance is essential for mastering Java's object-oriented features.

Editor's Notes

  • #2 Image source: https://www.simplilearn.com.cach3.com/tutorials/cpp-tutorial/single-inheritance-in-cpp.html
  • #3 Image source: https://www.acte.in/inheritance-in-java-article
  • #4 Image source: https://www.acte.in/inheritance-in-java-article
  • #5 Image source: http://www.programlover.com/python/python-types-of-inheritance
  • #6 Image source: https://www.vrogue.co/post/types-of-inheritance-single-inheritance-in-c-single-inheritance-only
  • #7 Image source: https://www.programiz.com/java-programming/inheritance
  • #8 Image source: https://www.geeksforgeeks.org/method-overriding-in-python/
  • #9 Image source: https://www.startertutorials.com/corejava/access-control.html
  • #10 Image source: https://www.researchgate.net/figure/Class-diagram-of-a-banking-application-using-PaDA_fig6_2547629
  • #11 Image source: https://www.codingninjas.com/codestudio/library/single-inheritance-in-java