• TestingDocs
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

Java Performance

Java Tutorials /

Improving Java Performance with Multithreading

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

‹ Types of Java Comments› Java Polymorphism

Recent Posts

  • How to secure your SQL Database: Tips and Tricks
  • Shaping the Future of Development: Exploring Key Trends in Software Engineering
  • Improving Java Performance with Multithreading
  • Difference between PHP and JavaScript?
  • Bing Conversation Styles
  • ChatGPT Introduction
  • Open Source AI Frameworks
  • Artificial Intelligence Tools
  • Top AI Music Applications
  • Top AI Website Design Tools

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com