Sunday, 18 December 2022

Multiple inheritance

 Write a program using multiple inheritance base class is shape and circle and triangle are derived class and calculate the area of triangle and area of circle.



class shape
{
    public void area()
    {
        System.out.println("Display area");
    }

}
class circle extends shape
{
    public void area (float r)
    {
       
        System.out.println(3.14*r*r);
    }

}
class trianle extends shape
{
    public void area (int l, int h)
    {
        System.out.println(0.5*l*h);
    }
}
public class singleinheritance
{
    public static void main (String args [])
    {
        circle c = new circle();
        c.area(5);
        trianle t=new trianle();
        t.area(4,4);
    }
}





OUTPUT: 
78.5
8.0

No comments:

Post a Comment

GitHub Most Imp Command For Every Developer Learn:

 Top Command for GitHub:  1) git clone 2) git init and git status   3) git add file name  or git add .  4) git commit -m message  5) git rem...