What is difference between Inheritance and abstract classes?
What is difference between Inheritance and abstract classes?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted May 15, 2015, 9:27 AM
Let us understand both
Inheritance is used to inherit all the method and fields of parent class. but
Abstract class is a special type of class which cannot be instantiated and acts as a base class for other classes. Abstract class members marked as abstract must be implemented by derived classes. The purpose of an abstract class is to provide a common definition of base class that multiple derived classes can share, and can be used only as a base class and never want to create the object of this class. Any class can be converted into abstract class by adding abstract modifier to it. Common features of an abstract class:
So if we want to create a class such that this class should be hide from user means user can not implement it direct then we should declare a class abstract and inherited by other class.Other diff is that if we have some method in base class that must be implemented in drived class that then we can marks this method as abstract class so this is only possible in abstract class.
Now a question arise when we use abstract class over inheritance . Ans is followings conditions we should use abstract class over simple inheritance
1.When independency of a class is not require in your application.
2. If there are certain members/ behaviors which are common to all classes, these should be placed inside the abstract class.
3. If we want to provide some method to base class which must be implemented in drived class then we can use concept of abstract class and make the method abstract. Which we want to implement in drived class.
In all other condition we should use InheritanceI hope my ans help you understand diff b/w both . If you have any query then you can ask i will try to solve ..
Thanks
MahaPosted May 15, 2015, 8:26 AM
Jagdev MishraPosted May 15, 2015, 8:14 AM
MahaPosted May 15, 2015, 7:59 AM
Inheritance means the particular characteristics received from parents through the genes .
If a statement, argument, or discussion is abstract, it is general and not based on particular examples.
Jagdev MishraPosted May 15, 2015, 7:27 AM
No Answer?