‎2008 Jul 24 8:14 AM
Hi,
Why theses are only allowed to declare in PUBLIC SECTION?
regards
‎2008 Jul 24 6:12 PM
Hi..
@ Everyone : This is a mis-conception that constructors can not be declared as Private ones. Constructors can be Public or Private methods both.
Check the article : http://www.abaplearning.com/index.php?option=com_content&view=article&id=35:abap-objects-singleton-c...
or Forum link : http://www.abaplearning.com/index.php?option=com_fireboard&Itemid=2&func=view&id=14&catid=6
Interfaces :
The interface methods are always public methods. This is because, the interface methods are called generally from outside the class.
A typical definition of interface is : "An interface defines the communication boundary between two entities, such as a piece of software, a hardware device, or a user. It generally refers to an abstraction that an entity provides of itself to the outside."
So you can understand that the methods on an interface are generally called by the outside world... so they have to be Public only !.
Think about it ... you will get it ..
Cheers.
‎2008 Jul 24 8:39 AM
Hii!
If you analyse the definition of constructor, they are automatically called at runtime with creation of runtime object. and your runtime object cannot access a private method directly.
I think, thats why they are declared in PUBLIC SECTION.
And,
Interface components can only be accessed by using an object reference whose class implements the interface. and object reference cannot directly access the private components.
Thats why the interface name is listed in the definition part of the class with INTERFACES statement in PUBLIC SECTION.
Regards
Abhijeet
‎2008 Jul 24 8:51 AM
Hi,
Interfaces have only method signaturs or declaration not definition we have to define definition in the class which implements inteface .
and for Constructor: When we create a object of a class then first it invokes the constructor of that class
Let say
Class B{A a = new a(); the constructor of class A is invoked first,
so it is necessary to make constructors public bty default.
Also have glance on this,
" The definition of a constructor looks much like the definition of any other subroutine, with three exceptions. A constructor does not have any return type (not even void). The name of the constructor must be the same as the name of the class in which it is defined. The only modifiers that can be used on a constructor definition are the access modifiers public, private, and protected. (In particular, a constructor can't be declared static.)"
Mohinder
‎2008 Jul 24 6:12 PM
Hi..
@ Everyone : This is a mis-conception that constructors can not be declared as Private ones. Constructors can be Public or Private methods both.
Check the article : http://www.abaplearning.com/index.php?option=com_content&view=article&id=35:abap-objects-singleton-c...
or Forum link : http://www.abaplearning.com/index.php?option=com_fireboard&Itemid=2&func=view&id=14&catid=6
Interfaces :
The interface methods are always public methods. This is because, the interface methods are called generally from outside the class.
A typical definition of interface is : "An interface defines the communication boundary between two entities, such as a piece of software, a hardware device, or a user. It generally refers to an abstraction that an entity provides of itself to the outside."
So you can understand that the methods on an interface are generally called by the outside world... so they have to be Public only !.
Think about it ... you will get it ..
Cheers.
‎2008 Jul 25 8:12 AM
Hello,
CONSTRUCTORS are usually public because a class instantiation is public by default (Properties tab in class builder). Change the class instantiation to private and you can make your CONSTRUCTOR private.
Cheers,
Mike
‎2008 Jul 25 8:21 AM
Hi
Unlike Classes there is no visiblity section in case of an Interface.
By default all the components in an Interface are of public scope. So, when we declare an interface in a
class we have to declare it in PUBLIC SECTION
As a rule Constructors should be decalred in PUBLIC SECTION of a class.
Hope this would help you.
Murthy
‎2008 Jul 29 8:17 AM
hi,
Constructors are special PUBLIC methods that are triggered when an object is instantiated from a class. They are necessary when you want to set the initial state of an object dynamically.
Like normal methods, there are two types of constructor - instance constructors and static constructors.
To use the instance constructor, the CONSTRUCTOR method must be declared in the public section of the class using the methods statement, and implemented in the implementation section.
Constructors must always be declared in the PUBLIC section of a class. Executed once for each instance.it is called automatically, immediately after the CREATE OBJECT statement..
It Can contain an interface with IMPORTING parameters and EXCEPTIONS , but cannot have any exporting/CHANGING/RETURNING parameters .
The interfaces are defined using the same syntax as for normal methods in the METHODS statement. To transfer parameters and handle exceptions, use the EXPORTING and EXCEPTIONS additions to the CREATE OBJECT statement .
Independent structures containing definition of its own components.
Incorporated in the public section of a class definition and the methods of the interface are implemented in the implementation section of that class.
Interfaces are included in the public section of a class.
have an implementation part, since their methods are implemented in the class that implements the interface.
‎2008 Jul 29 12:43 PM
hi,
interfacecomponents must be declared as public components.
if you do not do this ,
you risk the multiple implementations if a super class and sub class both implement the interface privately
hope this will clear your doubt.
construcor must be declared as a public method because this method will be called after create object statement is executed by the runtime system.
if it a private method it has to be called by a public method which is practically not posiible and will not serve the purpose of construcottor
hope this will calrify your doubt