java program 3:
itprofessionalsrocks.blogspot.com
java program 3:
a simple program demonstrating the concept of inheritance ..
class a
{
int i,j;
void show()
{
System.out.println("i and j"+i+""+j);
}
}
class b extends a
{
int k;
void showk(){
System.out.println("k:"+k);
}
void sum()
{
System.out.println("i+j+k:"+(i+j+k));
}
}
class inherit
{
public static void main(String args[])
{ a superob=new a();
b subob=new b();
superob.i=10;
subob.j=20;
subob.showk();
System.out.println("Contents of superOb") ;
subob.i=7;
subob.j=10;
subob.k=11;
System.out.println("Contents of subob");
subob.showk();
System.out.println("Sum of i,j,k in subob");
subob.sum();
}
}
java program 3:
a simple program demonstrating the concept of inheritance ..
class a
{
int i,j;
void show()
{
System.out.println("i and j"+i+""+j);
}
}
class b extends a
{
int k;
void showk(){
System.out.println("k:"+k);
}
void sum()
{
System.out.println("i+j+k:"+(i+j+k));
}
}
class inherit
{
public static void main(String args[])
{ a superob=new a();
b subob=new b();
superob.i=10;
subob.j=20;
subob.showk();
System.out.println("Contents of superOb") ;
subob.i=7;
subob.j=10;
subob.k=11;
System.out.println("Contents of subob");
subob.showk();
System.out.println("Sum of i,j,k in subob");
subob.sum();
}
}
Comments
Post a Comment