Inheritance Example 2 - Figure - Java

Program:
class figure
{
    int b;
    int l;
    figure(int x,int y)
    {
        l=x;
        b=y;
    }
}
class triangle extends figure
{
    triangle (int x,int y)
    {
        super(x,y);
    }
    int show()
    {
        return(l*b/2);
    }
}
class rectangle extends figure
{
    rectangle(int x,int y)
    {
        super(x,y);
    }
    int show()
    {
        return(l*b);
    }
}

class inheritance2
{
public static void main(String argrs[])
{
    figure fig1=new figure(4,5);
    triangle tri1=new triangle(4,5);
    rectangle rect1= new rectangle(4,5);
    System.out.println("Area of triangle="+tri1.show());
    System.out.println("Area of rectangle="+rect1.show());
}
}

Output:
nn@linuxmint ~ $ javac inheritance2.java
nn@linuxmint ~ $ java inheritance2
Area of triangle=10
Area of rectangle=20
nn@linuxmint ~ $

3 comments:

  1. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    internship program in banjarahills
    internship opportunities in banjarahills

    ReplyDelete
  2. I am DR. GURUJI NAVGRAHA from India a spell caster that has been successfully providing results to my clients for over many years. I use nothing but 100% safe and ancient Indian spiritual methods,I will reunite your ex partner back to you, stop an impending divorce or break-up, and bring back the passion, love, lust, communication and commitment between broken lovers. Don't live in a life unfilled without the one you truly desire. Let me show you the real results you've been searching for,My Powerful Indian

    Spiritual Spell are :
    wedding ritual, healing ritual,Divorce stop ritual,separation ritual,love ritual,protection ritual,self-confidence ritual,child ritual,success ritual,Return Lover ritual,restore passion ritual Save Marriage Spells,Prevent Divorce Spells,Cheating ritual Remove Ex ritual,Business increase,Money
    ritual,Famous ritual,Indian Spiritual Healing center is the answer
    Email: casterspell481@gmail.com
    Whatsap: +919108256518
    DR. GURUJI NAVGRAHA

    ReplyDelete
  3. informative blog , keep posting and dont forget to checkout our blog full stack course in satara

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...