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();
}
}
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
best but need output snap
ReplyDeleteVery interesting name you have mate. I'll think on your suggestion to add output snap. Thanks for comment, do visit again.
Delete