Sunday, 23 September 2012

Single Inheritance To Find Area Of Rectangle

Single Inheritance inherits the properties of one class into another class here is a program that implements single inheritance to find area of a rectangle..

/* Single Inhetitance To Find Area Of Rectangle */
class Dimensions
{
int length;
int breadth;
}

class Rectangle extends Dimensions
{
int a;
void area()
{
a = length * breadth;
}

}

class Area
{
public static void main(String args[])
{
Rectangle Rect = new Rectangle();
Rect.length = 7;
Rect.breadth = 16;
Rect.area();
System.out.println("The Area of rectangle of length "
+Rect.length+" and breadth "+Rect.breadth+" is "+Rect.a);
}
}

/* Output *

The Area of rectangle of length 7 and breadth 16 is 112 */

0 comments:

Post a Comment