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

Java

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/in/java/

Related Posts

Download Greenfoot Windows

Java /

Download & Install Greenfoot on Windows

Java /

Java Static Code Analysis

Java /

Java Testing Tools

Java /

Handle Multiple Exceptions in Java

Exceptions_In_Java

Java /

Exceptions in Java Programs

‹ Types of Java Comments› Java Polymorphism

Recent Posts

  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Print Triangle Pattern Flowchart
  • RAPTOR Editions
  • Flowgorithm Conditional Breakpoint Statement
  • Flowgorithm Read Numbers from File Example
  • Search Text File Flowchart Example
  • Flowgorithm Turtle Graphics Symbols
  • Draw Circle using Flowgorithm Turtle

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version