what is Abstract classes and abstract methods with example

Hi friends,i would like to share some important points about abstract classes and abstract methods with example
1)Abstract is a keyword which can be used with methods and classes
2)whenever a class is not providing full functionality then recommended to declare that class as "Abstract Class"
3)we cannot create a object of abstract class

name n=new name();//object is not possible
name n;//reference is possible
4)Refernce works with the help of chile class

name n=new gender();

5)abstract classes are similar to interfaces ,After declaring an abstract class,it cannot be instantiated on its own ,

it must be inhertited

6)a method without body is called as abstract method

syntax :  public abstract void findNumber();

7)Abstract method is also called as Rule

8)when a class contains atleast one abstract method ,then that class must he declard as abstract

9)All the methods must be override in derived classes.

10)Abstract classes provides a set of rules (Abstract methods)which must be followed in derived(overrided)

11)Abstract classes are not instantitable but a reference can be created.

12)In VB.net,abstract classes are created using "MustInherit" keyword.In C# we have "Abstract "implemented in the child class.

Example program on Abstract classes and abstract methods

abstract class shape
{
privates int x=3,y=5;
public void print()
{
messageBox.show(x+""+y);
}
public abstract void findarea();
}

class circle:shape
{
private int r=10;
public override void findarea()
{
double a=3.14*r*r;
MeesageBox.show("Area"+a);
}
public void display()
{
messagebob.show("Its completed");
}
}
code for button click
button_click()
{
circle c=new circle();
c.print();
c.findArea();
c.display();

//shape s=new shape();-->its show an error

shape s=new circle();
s,print();
s,findare();
s,display();-->Error
}
}
That's it....friends
developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Tanisha Sayyad

is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

4 comments:

 

Copyright @ 2013 Developers Code.

&