Thursday, 13 August 2015

Java Tutorial : Inheritance in Java

Enjoying This Java Lesson?

Subscribe to Ram N Java for more easy, beginner-friendly programming tutorials!

Subscribe on YouTube

What is Inheritance in Java?

Inheritance in Java is a core Object-Oriented Programming (OOP) mechanism where one object acquires all the properties (fields) and behaviors (methods) of a parent object.

It represents the IS-A relationship (also known as a Parent-Child relationship). With inheritance, you can create new classes built upon existing ones, allowing you to reuse fields and methods while adding new ones to the child class.

Why Do We Need Inheritance?

  • Code Reusability: Avoid writing duplicate code by reusing fields and methods from existing classes.
  • Method Overriding & Runtime Polymorphism: Easily customize inherited behavior to achieve runtime polymorphism.

Syntax & Real-World Example

To inherit from a class in Java, use the extends keyword:

class SoftwareEngineer extends Employee {
  // SoftwareEngineer inherits salary, run(), walk()
  // Plus adds bonus and talkAboutJava()
}

In this example:

  • Employee is the Superclass (Parent Class).
  • SoftwareEngineer is the Subclass (Child Class) that inherits all properties and methods from Employee.

Recommended Tutorials from Ram N Java


Click here to watch in Youtube :
https://www.youtube.com/watch?v=oRLUFOr8sak&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Inheritance in Java 
Java Tutorial : Inheritance in Java 
Java Tutorial : Inheritance in Java 
See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Tutorials