Single inheritance
- Creating sub classes from single super class is called single inheritance
--------------------------------------------------------------------------
Program : Single Inheritance
Program name : SingleInDemo.java
Output :
Parent i value is : 1
Child j value is : 2
class Parent
{
int i = 1;
public void m1()
{
System.out.println("Parent i value is : "+i);
}
}
class Child extends Parent
{
int j = 2;
public void m2()
{
System.out.println("Child j value is : "+j);
}
}
class SingleInDemo
{
public static void main(String args[])
{
Child c = new Child();
c.m1();
c.m2();
}
}
Compile : javac SingleInDemo.java
Run : java SingleInDemo
Output :
Parent i value is : 1
Child j value is : 2
--------------------------------------------------------------------------
Thanks for your time.
Thanks for your time.
Nireekshan