II B.Tech II Sem CSE Java Lab Exercise - 5a (Inheritance)

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

Web Development with PHP Course

  Course : Web Development with PHP The Importance Of PHP Web Development Website development is rapidly growing tool for business developme...