Google Search

Monday, October 10, 2011

Java Program for inheritance concepts


import java.io.*;
class a
{
int i,j;
void showij()
{
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.print("i+j+k="+(i+j+k));
}
}
class inheritance
{
public static void main(String args[])
{
a superob=new a();
b subob=new b();
superob.i=10;
superob.j=20;
System.out.println("contents of superob");
superob.showij();
System.out.println();
 subob.i=7;
 subob.j=8;
 subob.k=9;
System.out.print("contents of subob");
 subob.showij();
 subob.showk();
System.out.println();
System.out.print("sum of i j kin sub ob:");
subob.sum();
}
}

0 comments:

Post a Comment