How to apply oops concept here

Posted by Oswaldlily under ASP.NET on 3/28/2014 | Points: 10 | Views : 692 | Status : [Member] | Replies : 1
How to apply all 4 oops concept here?????
Encapsulation,Inheritance,Polymorphism,abstraction

public class shape
{

public void rectangle(int len,int breath)
{
area=len*breadth;
}
public void circle(int radius)
{
area=3.14&radius * radius;
}
public void square(int a)
{
area=a*a;
}


}




Responses

Posted by: Antonydurai on: 4/1/2014 [Member] Starter | Points: 25

Up
0
Down
Hi,

Just check it out

public abstract class shape
{
public int _area;
protected double radius;

public void setRadius(double r)
{
radius = r;
}


public abstract double Circle();

}
public class area:shape
{
public area(int len,int breadth)
{
_area= len * breadth;
}
public area(int a)
{
_area = a*a;
}
public override double Circle()
{
return 3.14 * radius * radius;
}
}

class Program
{
static void Main(string[] args)
{
var a = new area(5);
var b = new area(5,7);
b.setRadius(5);
Console.WriteLine("Area of Square: {0}",a._area);
Console.WriteLine("Area of Rectangle: {0}", a._area);
Console.WriteLine("Area of Rectangle: {0}", b._area);
Console.WriteLine("Area of Circle: {0}", b.Circle());
Console.ReadKey();
}
}

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response