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: 

What is the difference between abstract and interface?

Former Member
0 Kudos

and pls tell me how to know tat

wen to use static and instance

9 REPLIES 9

matt
Active Contributor
0 Kudos

An abstract class is one in which at least one method is abstract - i.e. defined to be abstract. It's implementation will be done by a subclass of the abstract class. And interface has all method abstract - no implementation at all. Interfaces are usually used where different types of object share certain common features. These features will be encapsulated in an interface.

Static refers to methods and attributes of a class that are common across all instances of that class, and are accessed without reference to an instance.

matt

0 Kudos

An abstract class can have methods with implementation and without implementation also the method without implementation is an abstract method which will be implemented in child class

interface at the top level only having definition u can implement this interface method in any class where u declare interface in the class

Former Member
0 Kudos

Hi,

Every class has an instance constructor called constructor. This is an exception to the rule that states that component names within an inheritance tree must be unique. However, the instance constructors of the various classes in an inheritance tree are fully independent of one another. You cannot redefine the instance constructor of a superclass in a subclass, neither can you call one specifically using the statement CALL METHOD CONSTRUCTOR. Consequently, no naming conflicts can occur.

The instance constructor of a class is called by the system when you instantiate the class using CREATE OBJECT. Since a subclass contains all of the visible attributes of its superclasses, which can also be set by instance constructors, the instance constructor of a subclass has to ensure that the instance constructors of all of its superclasses are also called. To do this, the instance constructor of each subclass must contain a CALL METHOD SUPER->CONSTRUCTOR statement. The only exception to this rule are direct subclasses of the root node OBJECT.

In superclasses without an explicitly-defined instance constructor, the implicit instance constructor is called. This automatically ensures that the instance constructor of the immediate superclass is called.

When you call an instance constructor, you must supply values for all of its non-optional interface parameters. There are various ways of doing this:

· Using CREATE OBJECT

If the class that you are instantiating has an instance constructor with an interface, you must pass values to it using EXPORTING.

If the class that you are instantiating has an instance constructor without an interface, you do not pass any parameters.

If the class you are instantiating does not have an explicit instance constructor, you must look in the inheritance tree for the next-highest superclass with an explicit instance constructor. If this has an interface, you must supply values using EXPORTING. Otherwise, you do not have to pass any values.

· Using CALL METHOD SUPER->CONSTRUCTOR

If the direct superclass has an instance constructor with an interface, you must pass values to it using EXPORTING.

If the direct superclass has an instance constructor without an interface, you do not pass any parameters.

If the direct superclass does not have an explicit instance constructor, you must look in the inheritance tree for the next-highest superclass with an explicit instance constructor. If this has an interface, you must supply values using EXPORTING. Otherwise, you do not have to pass any values.

In both CREATE OBJECT and CALL METHOD SUPER->CONSTRUCTOR, you must look at the next-available explicit instance constructor and, if it has an interface, pass values to it. The same applies to exception handling for instance constructors. When you work with inheritance, you need an precise knowledge of the entire inheritance tree. When you instantiate a class at the bottom of the inheritance tree, you may need to pass parameters to the constructor of a class that is much nearer the root node.

The instance constructor of a subclass is divided into two parts by the CALL METHOD SUPER->CONSTRUCTORstatement. In the statements before the call, the constructor behaves like a static method, that is, it cannot access the instance attributes of its class. You cannot address instance attributes until after the call. Use the statements before the call to determine the actual parameters for the interface of the instance constructor of the superclass. You can only use static attributes or local data to do this.

When you instantiate a subclass, the instance constructors are called hierarchically. The first nesting level in which you can address instance attributes is the highest-level superclass. When you return to the constructors of the lower-level classes, you can also successively address their instance attributes.

In a constructor method, the methods of the subclasses of the class are not visible. If an instance constructor calls an instance method of the same class using the implicit self-reference me->, the method is called as it is implemented in the class of the instance constructor, and not in any redefined form that may occur in the subclass you want to instantiate. This is an exception to the rule that states that when you call instance methods, the system always calls the method as it is implemented in the class to whose instance the reference is pointing.

Static Constructors

Every class has a static constructor called class_constructor. As far as the namespace within an inheritance tree, the same applies to static constructors as to instance constructors.

The first time you address a subclass in a program, its static constructor is executed. However, before it can be executed, the static constructors of all of its superclasses must already have been executed. A static constructor may only be called once per program. Therefore, when you first address a subclass, the system looks for the next-highest superclass whose static constructor has not yet been executed. It executes the static constructor of that class, followed by those of all classes between that class and the subclass you addressed.

with regards,

sowjanya.gosala

Former Member
0 Kudos

abstract class is not pure abstract.

but interface is pure(100%) abstract.

we can't create the object for both of them.

Former Member
0 Kudos

abstract class is not pure abstract.

but interface is pure(100%) abstract.

we can't create the object for both of them.

Former Member
0 Kudos

Hi Chandra Sekar,

ABSTRACT: In the abstract class we can only define the methods and we cannot implement the body that means we cannot write code in that method.After inheriting that method in subclass only we have to write code for that method.

INTERFACE:It is possible to write the code in the method at the time of defing the method..

Reward points if helpful.

Kiran Kumar.G.A

Have a Nice Day..

Former Member
0 Kudos

[Abstract|http://www.cegonsoft.com/jobassistanceprogram.php] class is a class that can not be instantiated, it exists extensively for inheritance and it must be inherited. There are scenarios in which it is useful to define classes that is not intended to instantiate; because such classes normally are used as base-classes in inheritance hierarchies, we call such classes abstract classes.

More Details : [Abstract|http://www.aboutcegonsoft.com/]

ravi_lanjewar
Contributor
0 Kudos

Abstract class can have single inheritance and Interface can have multiple inheritance.

Class can have abstract method, which implementation not done itself and subclasses can do. it means class can partial abstract but not in case of interface.

Kind Rgds

Ravi Lanjewar

0 Kudos

Regards,

Snehal.