Single-Level Inheritance

Single-level inheritance: When a class extends another class then it is known as Single-Level Inheritance.

Single Level Inheritance
Single Level Inheritance


1.Example of Inheritance

import java.util.*;
class super
{
int a=10;
void Display_Super()
{
System.out.println("Display on super class:- Value of a is"+a);
}
}
class Sub_class extends Super_class
{
void Display_sub()
{
System.out.println("Display on Sub Class:-Value of a is"+a);
}
}
class Single
{
public static void main(String args[])
{
Sub_class sub1=new Sub_class();
sub1.Display_Super();
sub1.Display_sub();
}
}
OUTPUT:
Display on super class:-Value of a is 10
Display on Sub Class:-Value of a is 10
Translate »