Single Inheritance To Find Area Of Rectangle

3 comments - Post a comment

--BY Joel Mathias
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 */

 
This Post has 3 Comments Add your own!
Anonymous - August 5, 2011 at 10:17 AM

Nice Program dude ,very easy to undesrstand ,thanx

Anonymous - July 1, 2012 at 11:40 AM

Krishana Chaitanya You didn't understand the Interface concept. Here the we are all talk about Interface. We use this only to multiple inheritance. But you gave multilevel of inheritance. don't confuse multiple with multilevel.

Anonymous - August 25, 2012 at 12:20 PM

hmmmmm very easy to understand

Post a Comment