Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Object of an abstract class

Former Member
0 Kudos

Can we create object of an abstract class ?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello

Conceptually, we cannot create instance for an abstract class.

But, we can create object of the abstract class, do follow the below syntax.

create object <Ref to Abstract class> TYPE <Non Abstract class name>.

Hope this will help you

Subin

4 REPLIES 4

Former Member
0 Kudos

Please read SAP Help before posting.

We cannot create object of abstract class.

Check this link from SAP help to know more :

http://help.sap.com/saphelp_nw70/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm

Hope this helps you.

Edited by: Harsh Bhalla on Dec 19, 2009 3:58 PM

Former Member
0 Kudos

Hello

Conceptually, we cannot create instance for an abstract class.

But, we can create object of the abstract class, do follow the below syntax.

create object <Ref to Abstract class> TYPE <Non Abstract class name>.

Hope this will help you

Subin

rb
Active Participant
0 Kudos

That does not create an object of the abstract class! It does create an object of a class which should be a sub class of the abstract base class. This could be used for dynamic instantiation or so.

@ Thread starter: You should the abstract class is normally a base class. You derive a sub class from this base class and implement or redefine the methods of the base class.

If you dont want created your own sub class, just look if the abstract class have been implemented. Maybe you can use the existing implemantations.

Bye Richard

naimesh_patel
Active Contributor

As Richard Brünning mentioned in his reply, we can't instantiate the object with reference to the Abstract Class. i.e.


DATA: O_OBJ TYPE REF TO ZCL_ABS_CLASS.
CREATE O_OBJ.   " << This will give syntax error

But you can surely use the abstract class to reference the object. At run time, based on your required you can instantiate the object with actual reference type to the subclass of the abstract class. Like:


DATA: O_OBJ TYPE REF TO ZCL_ABS_CLASS.
* ZCL_ABS_CLASS_SUB is sub class of the ZCL_ABS_CLASS
CREATE O_OBJ TYPE ZCL_ABS_CLASS_SUB.

Regards,

Naimesh Patel