--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 */
Labels: Core Java, Inheritance
Subscribe to:
Post Comments (Atom)
Nice Program dude ,very easy to undesrstand ,thanx
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.
hmmmmm very easy to understand