Your Only Destination To Empower Your Computer Programing Knowledge. Sky is not so high, You can Touch it if You Try

Program to show the concept of inheritance using super keyword.

class A
{
int length;
int breadth;
void A1(int x, int y)
{
length=x;
breadth=y;
}
}
class B extends A
{
int height;
int volume(int x,int y,int z)
{
super.A1(x,y);
height=z;
return (length*breadth*height);
}
}
class Inher
{
public static void main(String ar[])
{
B h=new B();
int volume1=h.volume(2,1,3);
System.out.println("volume is="+volume1);
}
}

Output:-


C:\Documents and Settings\Administrator>cd\

C:\>cd java

C:\java>cd bin

C:\java\bin>javac Inher.java

C:\java\bin>java Inher
volume is=6

C:\java\bin>

No comments:

Post a Comment