Thursday, March 31, 2011

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,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()
public abstract void findarea();

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

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

shape s=new circle();
That's it....friends
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.

Labels: , , , ,


At March 31, 2011 at 8:06 PM , Blogger Dotnet Tutorials said...

Hey Thanks for sharing yaar..........

At April 11, 2011 at 2:16 PM , Anonymous Anonymous said...

Good One...

At May 4, 2011 at 7:59 PM , Blogger balu said...

nice article

At June 28, 2011 at 10:16 AM , Anonymous balu said...

nice article


Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home