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: 

oobj

Former Member
0 Kudos

what is the difference between class and instance

5 REPLIES 5

former_member223537
Active Contributor
0 Kudos

Class eg. CIRCLE which has two methods diameter & area

Instance is an object of the class. There can be as many instance of the class as required.

Instance : eg. Ball, Circular Table etc

Former Member
0 Kudos

Hello,

<b>CLASS</b>

Class is a collection of objects

You can define classes and interfaces in ABAP Objects either globally or locally. You define global classes and interfaces using the Class Builder (Transaction SE24) in the ABAP Workbench. These are then stored centrally in the class library within the R/3 Repository. All ABAP programs in the R/3 System can access global classes and interfaces. You define local classes and interfaces within an ABAP program. They can only be used in that program. When you use a class in a program, the system first looks for a local, then for a global class with the specified name. There is no other distinction in using global and local classes or interfaces.

For local classes, which are only used in one program, it is sufficient to define the public interface (the components that are visible externally) so that it suits the program. Global classes, on the other hand, must be usable system-wide. Therefore the public interface of a global class can only be typed with reference to data types that are visible system-wide.

The following sections describe how to define local classes and interfaces in an ABAP program. For information about global classes and interface, refer toClass Builders in the ABAP Workbench documentation.

Defining Local Classes

Local classes consist of ABAP code, enclosed between the CLASS - ENDCLASS statements. A complete definition contains a declaration part and, if required, an implementation part.

The declaration part of a class class contains the statement block

CLASS class DEFINITION.

...

ENDCLASS.

The declaration part contains the declaration of all of the components (attributes, methods, events) of the class. You must explicitly assign all of these to a visibility section (PUBLIC SECTION, PROTECTED SECTION, PRIVATE SECTION), which defines the accessibility of the components that it contains. The declaration part of a local class is part of the data declaration, and should therefore occur at the beginning of the program.

If you declare methods in the declaration part of the class, you must also write an implementation part. This consists of the statement block

CLASS class IMPLEMENTATION.

...

ENDCLASS.

The implementation part contains implementations of all of the methods of the class. As procedures methods are processing blocks of the ABAP program. It is therefore not important how the implementation part is arranged in the source code. For better readability, however, all implementation parts of local classes should appear at the end of the program (similar to the definition of subroutines) or immediately after the associated definition part. In the second case, however, please note that subsequent non-declarative statements must be assigned explicitly to a processing block such as START-OF-SELECTION in order that they can be reached.

<b>Objects</b>

Objects are instances of classes. All transient objects exist within the context of an internal session (memory area of an ABAP program). Persistent objects in the database are not available in Release 4.6A. You can create any number of objects (instances) for a class. Each one has a unique identity and its own attributes.

Creating Objects

To create an object, you need a object reference variable that can refer to the required class:

Once you have declared a class reference variable obj for the class class , you can use the CREATE OBJECT obj statement to create an object. The statement creates an instance of the class class, and the reference variable obj contains a reference to the object.

Once you have declared a class reference variable obj for a superclass of the class class or an interface reference variable obj for an interface which is implemented by the class class, you can use the addition TYPE class of the statement CREATE OBJECT obj to generate an instance of the class class.

Reward if helpful,

Regars,

LIJO

Former Member
0 Kudos

Hi

<b>multiple instances of a "class", such as a vehicle, is one of the central

attributes of object-oriented languages.</b>

0 Kudos

Hi,

Simple example

If <b>HUMAN</b> is a class <b>You</b> are an instance.

Class is not physical, Instance is physical it occupies memory in ABAP.

Regards,

Sesh

Former Member
0 Kudos

hi,

class : its like a structure which holds all data members and member functions.

it doesn't occupy any memory

it cant access its objects . Inorder to access we have to create a instance.

instance: it occupies the memory based on the objects represents in class.

its logical reprsentation of all items in a class.

using instance only we can access all public and protected members of a class.

if helpful reward some points.

with regards,

Suresh Aluri.