Originally posted by saisreereddy surabhi: hi. can anyone explan me about abstract class.......and i have no idea about abstract classes before
An abstract class is a class that can't be instantiated. In general, you would want to make a class abstract, when some of the methods of the class are not implemented (abstract methods). This will allow your class to compile, but not directly used.
To use your abstract class, you would have to subclass from the abstract class, and implement the abstract methods.
For design reasons, there may also be other reasons why you don't want a class to be instantiated -- maybe certain methods has been implemented but incomplete.
Let us go by an example.. Imagine, you are asked to create horse, dog etc. Obviously, you would design classes like Horse, Dog etc. right? But, how many such individual classes would you design to match the entire animal kingdom? Wouldn't it be silly to repeat all the common(like eat, sleep, run etc) animal specific code for each class that you design? Smart you are.. you would simply pick out the common behavior and make it one class called "animal"! Yup, that's right.. you just want to put everything an animal is supposed to have in "animal" class. Now, imagine, someone is trying to create an instance of animal! Uh oh!! What would be that animal look like? Dog? Horse? Else what? There you are.. an animal class is not supposed to allow its instances. You should make be precise about your animal thing before you actually make an instance. Well, the animal class is now called as abstract class. It is just a concept or idea not associated with any specific instance. Other examples for abstract classes include humanbeing, employee, shape, etc.