- When a class is not providing full functionality it recommended to declare that class as an Abstract class.
- Method with out body is called an abstract method.
- Ex: public abstract void GetArea ();
- When class contain at least one abstract method then that class must be declared as abstract class.
- All the abstract method must be overridden in the derived class.
- We cant create object for Abstract class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class AbstractClassSammple : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Circle c = new Circle ();
c.print();
Response.Write(c.findarea()+" ");
Response.Write("
"+c.print());
}
}
public abstract class Shape
{
private int x = 10;
private int y = 20;
public int print()
{
return (x + y);
}
public abstract double findarea();
}
public class Circle : Shape
{
private int r = 10;
public override double findarea()
{
double a = 3.14 * r * r;
return (a);
}
}
No comments:
Post a Comment