a)Implementing Single Inheritance
Aim: To write a JAVA program to implement Single Inheritance
Description:
Program:
class Shape
{
int length;
int breadth;
}
class Rectangle extends Shape
{
int area;
public void calcualteArea()
{
area = length*breadth;
}
public static void main(String args[])
{
Rectangle r = new Rectangle();
r.length = 10;
r.breadth = 20;
r.calcualteArea();
System.out.println("The Area of rectangle of length \""
+r.length+"\" and breadth \""+r.breadth+"\" is \""+r.area+"\"");
}
}
Output:
No comments