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: 

Abstract Class and Interface

Former Member
0 Kudos

Please tell me what is Abstract Class and Interface. Please explain with help of simple example and also tell me difference between them.

4 REPLIES 4

Former Member
0 Kudos

An abstract class is the one that is not used to create objects. An abstract class is designed to act as a base class (to be inherited by other classes). Abstract class is a design concept in program development and provides a base upon which other classes are built. Abstract classes are similar to interfaces. After declaring an abstract class, it cannot be instantiated on it's own, it must be inherited. Like interfaces, abstract classes can specify members that must be implemented in inheriting classes. Unlike interfaces, a class can inherit only one abstract class. Abstract classes can only specify members that should be implemented by all inheriting classes.

Interfaces

Under the hood, an interface is like a class with some restrictions.

1. All its methods must be abstract instance methods, no static methods allowed.

2. Yet, all the variables defined in an interface must be static final, i.e. constants. Happily the values need not be known at compile time. You can do some computation at class load time to compute the values. The variables need not be just simple ints and Strings. They can be any type.

3. No static initialiser blocks. You must do your initialisations in one line per variable. And, of course, no static initialiser helper methods defined in the interface. If you need them, them must be defined outside the interface.

uwe_schieferstein
Active Contributor
0 Kudos

Hello

The methods of an abstract class may contain default implementations for the sub-classes. The same is not possible with interface methods which are always empty.

Regards

Uwe

Former Member
0 Kudos

Hi

i am sending the link.That contains the information.

http://www.sap-img.com/java/when-we-go-for-abstract-and-interface.htm

Former Member
0 Kudos

hi

i will suggest u to refer some basic java book , to clear ur basic concept of OOPS , because these principal remain same for all languages that follow OOPS concept .

and under standing these with java is easier then with ABAP .

Abstract Class

class which have atleast 1 method which is declared only , (no definition is given for it in this class is mentioned as Abstract Method )

and that class is defined as Abstract class

Interface :

only declaration of method done here , no method will be defined here , class which will implement this interface will give definition .

Diff. b/w Abstract Class and Interface :

ABS Class can have method with there definition , but one method should be there with declartion only.

Interface will have all method with out definition .

hpoe this help u .

reward if helpful.