TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java Tutorials

Java Inheritance

Overview

In this tutorial, we will learn about Java Inheritance. Inheritance is a mechanism used to develop new classes by extending the existing classes. The main advantage of inheritance is the reusability of code. In Java we used the extends keyword to extend from the existing class.

extends keyword

The keyword extends is used by the child class to inherit the features of the parent class.

public class <child_class> extends <parent_class> {
…

}

Example:

public class B extends A {
…
}

 

Java Inheritance

The existing class is known as the parent class or the superclass. In this example, A is the parent class. The inherited class is known as the subclass or the child class. B is the sub-class.

Inheritance defines an ‘is-a’ relationship between the parent class and the child class. Inheritance is a transitive relationship.

Employee is-a Person

Example:

public class Employee extends Person {
…
}

—

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

Related Posts

Download Greenfoot Windows

Java Tutorials /

Download & Install Greenfoot on Windows

Java Tutorials /

Java Static Code Analysis

Java Tutorials /

Java Testing Tools

Java Tutorials /

Handle Multiple Exceptions in Java

Exceptions_In_Java

Java Tutorials /

Exceptions in Java Programs

‹ Types of Java Comments› Java Polymorphism

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com