Tuesday 19 January 2016

Why we cannot create object of abstract class?


If a class use keyword ‘abstract’ then it cannot be instantiated and can only be used as  base class.

Abstract class is like a template or an empty or partially empty structure, you have to extend it and build it before you can use it.
Example:-  let’s take an example animal abstract class. There are no such things as real animal. There are specific types of animal. You can instantiate cow and elephant and tiger but you cannot instantiate plain animal. So we create derived class from base class with different functionality like ‘makesound()’ but cannot be defined as base class level. So that it is not possible to create object of abstract class.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.