Super Keyword in Java

 Super Keyword in Java


// Super Keyword


class Rectangle

{

int l, b;

Rectangle(int x, int y)

{

l = x; 

b = y;

}

void fnArea()

{

System.out.println("Area = "+(l*b));

}

}


class Box extends Rectangle

{

int h;

Box(int x, int y, int z)

{

super(x,y);

h = z;

}

void fnVolume()

{

System.out.println("Length = "+super.l);

System.out.println("Breadth = "+super.b);

super.fnArea();

System.out.println("Volume = "+(l*b*h));

}

}


class SuperKW1

{

public static void main(String as[])

{

Box obj = new Box(2,3,4);

obj.fnVolume();

}

}


No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu