Here is the listing of Java programming examples on Inheritance.
1. Java Examples on Inheritance Class
Inheritance is a mechanism wherein a new class is derived from an existing class. THIS Keyword is a reference variable in Java that refers to the current object. Super keyword is a reference variable which is used to refer immediate parent class object. Method overriding is a feature in which a class can provide an implementation of a method that is already provided by one of its parent classes. This section contains Java programs on inheritance class using This Keyword and Super Keyword. It also shows method overriding in a class using inheritance classes.
Java Program to Use This Keyword in Inheritance Class
Java Program to Use Super Keyword in Inheritance Class
Java Program to Show Method Overriding in a Class Using Inheritance Class
Java Program to Check if a Given Class is Inheritance
2. Java Examples on Inheritance Using Super Class
In the terminology of Java, a class that is inherited is called a superclass. The class that does the inheriting is called a subclass. Each class has a super class and it can have one or more sub classes. Super() invokes the constructor of immediate parent class. constructor is a method used to initialize an object. Constructor that has no parameter is known as default constructor. constructor that has parameters is known as parameterized constructor. This section contains Java programs on accessing super class in method overriding, checking super class method is non abstruct or not, checking default and parameterized constructors of super class.
Java Program to Access Super Class in a Method Overriding
Java Program to Check If Given Super Class Method is Non Abstruct
Java Program to Check if the Default Constructor of Super Class is Available to SubClass by Default
Java Program to Check if Parameterized Constructor of the Super Class can be Called from SubClass Using Super()
3. Java Examples on Inheritance Types
Inheritance means access the properties and features of one class into another class. Java supports mainly 3 types of inheritance they are Single Inheritance, Multilevel Inheritance and Heirarchical Inheritance. Java does not support multiple inheritance, but supports partially through interfaces. A derived class with only one base class is called single inheritance. A derived class with one base class and that base class is a derived class of another is called multilevel inheritance. One class directly extends more than one class is called multiple inheritance. This section contains Java programs on single inheritance, multi level inheritance and limitation of multiple inheritance. It also contains programs on handling arithmetic operations through inheritance.
Java Program to Show the Concept of Single Inheritance
Java Program to Find Average of 4 Different Using Multi Level Inheritance
Java Program to Illustrate Limitation of Multiple Inheritance
Java Program to Handle Arithmetic Operation Through Inheritance
4. Java Examples on Inheritance Using Abstract Classes
An abstract class can have abstract and non-abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. A class has to be declared abstract to have abstract methods. Abstract keyword is used to create a abstract class and method. Reference variables are used to refer an object. They are declared with a specific type which cannot be changed. This section contains Java programs on defining reference variables and static members for abstract class, defining abstract class without using abstract method, defining constructor for abstract class without creating a object.
Java Program to Define the Reference Variable for the Abstruct Class
Java Program to Show How to Access the Static Member of the Abstruct Class
Java Program to Define the Method as Abstruct then While the Class Must be Define as Abstruct
Java Program to Define the Abstruct Class Without Abtruct Method
Java Program to Define the Constructor for the Abstruct Class Without Creating an Object
5. Java Examples on Inheritance Using Abstract Method
Abstract method is a method that is declared, but contains no implementation. Abstract class can have abstract and non-abstract methods. A method must always be declared in an abstract class. Abstract methods body implementation is provided by the subclass. Abstract methods can never be final. Abstract modifier is placed before classes or methods. This section contains Java programs on abstract methods and checking given method has static members and abstract modifiers.
Java Program to Check if Given Method as Static Member Without Using Abstruct Method
Java Program to Check if Given Method as Abstruct Modifier
Java Program to Define the Body for the Abstract Method
6. Java Examples on Interfaces
Interface is a reference type which is similar to class. It is a collection of abstract methods and static constants. Interface is mainly used to achieve abstraction. Interfaces are designed to support dynamic method resolution at run time. One interface can inherit another by use of the keyword extends. This section contains Java programs on interface implementation, use of interface in enum, finding the are of circle and square using interfaces, achieving multiple inheritance using multiple interfaces.
Java Program that Show the Implementation of Interface
Java Program to Check if Given Class is Inherite Class Using Interface
Java Program to Illustrate Achieve Multiple Inheritance Using Multiple Interfaces
Java Program to Use of Interface in Inner Class and Enum
Java Program to Find Area of Square and Circle Using Interface Where Two Class for Circle and Rectangle and One Interface
7. Java Examples on Packages & Access Modifiers
Package is a namespace that organizes a set of related classes and interfaces. Access modifiers in Java are private, default, protected and public. When no access modifier is specified for a class is called default, Private access modifier is specified using the keyword private. Public access modifier is specified using the keyword public. Protected access modifier is specified using the keyword protected. This section contains Java programs on importing classes using other packages, understanding private and protected members in sub class, finding the area of square and rectangle from Shape.
Java Program to Show Importing of Classes from Other User Define Packages
Java Program to Find the Area of Square and Rectangle by Deriving them from Shape
Java Program to Understand Private Members are Not Accessible in Sub Class, but Protected Members are Available in SubClass