In this article you will learn about basic interview questions on SAP ABAP Object Oriented Programming that will be useful when attending interviews.
SAP ABAP OOPS Interview questions
1. Can abstract class have both abstract and non-abstract methods ?
Yes, an abstract class can have both abstract methods (methods without implementation) and non-abstract methods (methods with implementation). This allows for shared functionality while enforcing specific implementations in derived classes.
2. Keyword to call superclass method from subclass ?
The keyword is `SUPER->`. It is used to call a method of the superclass from within a subclass.
3. Can a static method access instance attributes ?
No, a static method cannot directly access instance attributes because it belongs to the class itself, not to any specific object. Instance attributes are tied to objects, and static methods operate independently of objects.
4. What's the default visibility of methods in interfaces ?
Methods in interfaces have a default visibility of `PUBLIC`. This means they are accessible wherever the implementing class is used.
5. Can you instantiate an abstract class ?
No, you cannot instantiate an abstract class directly because it is incomplete and meant to be inherited. You must create a subclass and instantiate that.
6. Which method runs automatically on object creation ?
The `CONSTRUCTOR` method runs automatically when an object is created. It is used for initializing the attributes of the object.
7. What’s the purpose of CLASS-CONSTRUCTOR ?
The `CLASS-CONSTRUCTOR` method is used to initialize static attributes or perform actions that need to occur once when the class is loaded into memory.
8. What's the difference between DATA and CLASS-DATA in ABAP OOP?
- `DATA`: Used to define instance attributes, tied to specific objects.
- `CLASS-DATA`: Used to define static attributes, shared across all instances of the class.
9. Can we have multiple CONSTRUCTOR methods in one class ?
No, a class can have only one `CONSTRUCTOR` method. However, you can have overloaded methods for additional initialization.
10. What's the syntax to raise an exception of class `cx_error`?
```abap
RAISE EXCEPTION TYPE cx_error EXPORTING ... .
```
You specify the exception class and optionally pass additional parameters.
11. Can two classes implement the same interface ?
Yes, two or more classes can implement the same interface. This is a key feature of interfaces known as polymorphism, allowing different classes to provide their own implementation of the defined methods.
12. What is the ME keyword used for ?
`ME` refers to the current instance of the class. It is used to access instance attributes or methods from within the class.
13. What is polymorphism in ABAP OOP ?
Polymorphism allows methods to behave differently based on the object that calls them. It is achieved using inheritance and interfaces, enabling dynamic method binding.
14. Can interfaces have attributes ?
No, interfaces cannot have attributes. They are purely meant for defining methods that implementing classes must provide.
15. Is method overloading supported in ABAP ?
No, ABAP does not support method overloading (having multiple methods with the same name but different parameters). Instead, you can achieve similar functionality using optional parameters.