Skip to content

axitchandora/ME_INHERITANCE_JAVA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

ME_INHERITANCE_JAVA

A Project Repository for Inheritance Byte in Java

Summary of Inheritance

  • Why is it useful? - It helps separate out common functionality and fields so that they can be reused across many other classes cleanly. Avoids code redundancy.
  • Where to apply? - In the code base when different objects need to share common fields and functionality.
  • How to apply? - Define a parent class with all shared functionalities & child classes that inherit these from the parent class.
  • What is the drawback if we don’t use inheritance? - Code duplication, Higher maintenance cost.

Types of Inheritance

  • Types of Inheritance

  • Single inheritance

  • Multiple inheritance

  • Hierarchical inheritance

  • Multilevel inheritance

  • Hybrid inheritance

Practical Scenarios

  • Java Collections is a good example of application of inheritance.

image

  • Java Exceptions is among one of the notable Class hierarchies displaying the effective use of inheritance.

image

General rules of Inheritance

  • A class (child class) can extend another class (parent class) by inheriting its features.
  • Implements the DRY (Don’t Repeat Yourself) programming principle.
  • Improves code reusability.

Inheritance vs Composition

  • Composition is another way to reuse code from another class. It is achieved by creating a class containing instances of other classes that implement the desired functionality, rather than inheritance from a base or parent class.
  • Further Reading:- Inheritance Vs Composition (veerpalbrar.github.io)

Encapsulation and Abstraction vs Inheritance

  • Encapsulation and Abstraction are helpful to develop and maintain a big codebase.
  • When there are similar objects in this big codebase that share common functionality, the common functionality and fields can be separated out into a separate base class which is then inherited by child classes.

About

A Project Repository for Inheritance Byte in Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages