Jump to content

Why we can not create the object of the Abstract class?


pr.nimbalkar
 Share

Recommended Posts

Because that's what the abstract class is for - specifying a set of methods a child class must implement on its own, while also allowing you to specify default implementations for some methods if you so desire.This of it like that - you have a system that accepts "plug-ins" that are defined by a class that inherits your abstract class. Why would you ever want to load a plug-in that doesn't do anything beyond the defaults (if any)? You wouldn't... you'd expect the plug-in creator to define the methods you expect, and then call them from within your system to actually let the plug-in do its thing. If you could instanciate an abstract class, you'd essentially load an empty plug-in.You could actually not use abstract classes, and just use normal classes. However, they won't allow you to define the methods a class must implement, which is where your system may start breaking.

Link to comment
Share on other sites

Hi pr.nimbalkbar, The Abstract class have one or more abstract method.And the abstract method can't to be implement in Abstract class.So can't create abstract class object. If you want create a new Abstract class object, you will Create a new class extends Abscract class and implement abstract method. The final code as follows: -------------------------------------------- AbstractClass obj = new SubClass(); -------------------------------------------- I don't Know whether,php like C# or Java. But I think that's OO knowledge.

Edited by AlexYan
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...