Single Inheritance : In the case of Single Inheritance, we derive the single derived class, on the basis of the single base class.
PROGRAM
class A
{
private int a;
public void
setA(int i)
{
a=i;
}
public void
showA( )
{
System.out.println("a="+a);
}
}
class B extends A
{
private int b;
public void
setB(int j)
{
b=j;
}
public void
showB( )
{
System.out.println("b="+b);
}
}
class SingleDemo
{
public static
void main(String args[ ])
{
B ob=new B( );
ob.setA(5);
ob.setB(10);
ob.showA();
ob.showB();
}
}
Comments
Post a Comment