Abstract Class:-
- It's a class which is not fully implemented i.e, Contains atleast one abstract method.
- Abstract method is a method which is just declared but not implemented.
- We declare a method as abstract when we are not sure about to implementation .but it is sure that other classes has to use the same method.
- If a class contains one abstract method class also should be declared as abstract which is done by using the key word "ABSTRACT".
- Abstract method always declared in public and protected section.
- The sub class which ever inherits the abstract class must take the responsibility of implementation of the abstract methods of the abstract class other wise subclass also should be declared as abstract.
- The implementation of the abstract method is a specific to the class which ever implements it.
- Abstract class cannot be instantiated because they are not fully implemented.
(Abstract method also called as NON-CONCRETE methods)
Example:
Report ZRDD_OOPS30.
class course definition abstract.
public section.
methods : setcourse abstract, "non concrete methods
displaycourse. "concrete methods
protected section.
data : coursename(10) type c,
coursefees type i,
courseduration type i.
endclass.
class course implementation.
method displaycourse.
write :/ coursename,
coursefees,
courseduration.
endmethod.
endclass.
class genesis definition
inheriting from course.
public section.
methods setcourse redefinition.
endclass.
class genesis implementation.
method setcourse.
coursename = 'Abap'.
coursefees = 10000.
courseduration = 4.
endmethod.
endclass.
class emax definition
inheriting from course.
public section.
methods setcourse redefinition.
endclass.
class emax implementation.
method setcourse.
coursename = 'Abap'.
coursefees = 8000.
courseduration = 5.
endmethod.
endclass.
start-of-selection.
data c type ref to course.
data g type ref to genesis.
create object g.
write :/ 'GENESIS'.
call method : g->setcourse,
g->displaycourse.
write :/ 'COURSE ---> GENESIS'.
c = g.
call method : c->setcourse,
c->displaycourse.
data e type ref to emax.
create object e.
write :/ 'EMAX'.
call method : e->setcourse,
e->displaycourse.
write :/ 'COURSE ---> EMAX'.
c = e.
call method : c->setcourse,
c->displaycourse.
No comments:
Post a Comment