Announcement:

This is just the beginning of this blog, please don't copy any of my posts.

Sunday 23 December 2012

[Java] program to calculate and display area of Square and Rectangle using function overloading

Define a class Shape having overloading static member function area() to calculate and display area of Square and Rectangle.
class Shape
{
static int l,b,S,R;
static void area(int m)
{                                                                                                  //For Square
l=m;     
}

static void area(int x,int y)
{
l=x;                                                                                            //For Rectangle
b=y;
}

void cal()

{
S=l*l;
R=l*b;
}

void display()
{
System.out.println("Area of Square="+S);                       //For Display
System.out.println("Area of Rectangle="+R);
}

public static void main(String args[])
{
Shape s1=new Shape();                                                       //Object s1 of class Shape is created.
area(10);
area(10,2);                                                                             // area() is called .
s1.cal();
s1.display();
}
}
Share it Please

Pankaj Gaikar

Pankaj Gaikar is a professional blogger from Pune, India who writes on Technology, Android, Gadgets, social media and latest tech updates at Punk Tech , Being Android & Shake The Tech . Email me HERE

2 comments :

  1. Replies
    1. Very interesting name you have mate. I'll think on your suggestion to add output snap. Thanks for comment, do visit again.

      Delete

Copyright @ 2013 Pune University Bachelor of Engineering . Designed by Pankaj Gaikar | Love for The Tricks Machine