‎2012 Jan 17 12:14 PM
Hi experts,
I just got to know, we can make a class abstract as well as final, but i din't get to know in which situation we use this.
As final class cannot be inherited and abstract class cannot have an instance of its own and has to be inherited.
So please guide me if this is really necessary and if so when ??
‎2012 Jan 17 12:22 PM
When you need a class with only static components you can make it both abstract and final. as you do not need to instantiate the class for using static components.
‎2012 Jan 17 12:22 PM
When you need a class with only static components you can make it both abstract and final. as you do not need to instantiate the class for using static components.
‎2012 Jan 17 12:48 PM
Hi,
'abstract' and 'final' concern different class attributes.
You define class as Final, when You do not want others to extend Your class.
Good example is ZCL_MATH with SUM(x,y) method. Class ZCL_MATH should be final.
Otherwise You could create ZCL_MATH_2 class (inheriting from ZCL_MATH),
and change SUM(x,y) method. Class ZCL_MATH_2 can be used everywhere,
where ZCL_MATH is required and change the result of addition!
Abstract classes are like template - You can create other classes based on the abstract class
and provide special functions.
An example: abstract class ZCL_VEHICLE (with attributes like name, owner, medhods GET_MAX_SPEED, etc.) can not be instanciated, but subclasses ZCL_CAR, ZCL_BIKE, ZCL_BUS can be. They represent physical object.
Regards,
--
Przemysław
‎2012 Jan 18 6:42 AM
‎2012 Jan 18 7:39 AM
Hi,
When you define a class and you don't want to inherit any child class from that class you will make it FINAL.
When you define a class and it's method's implementation is not done in the same class but is done in the inherited class(childclass) you will make the class as ABSTRACT.
example for ABSTRACT.
you define a class object and include a method called draw object and you won't implement it here.
now you make subclasses of this class( like circle, square, triangle etc.) and implement your code here for drawing that object.
Hope this helps a little in understanding ABSTRACT and FINAL.
Regards.
Aswath.
‎2012 Jan 20 12:42 PM
Hi Suresh,
When I came across this concept of having a class ABSTRACT and FINAL at the same time even I was bit surprised. Because abstract and final are totally opposite in terms of functionality as a ABSTRACT and FINAL class caanot be instantiated and at the same time it would not be inherited by any other sub class as it is a final. The only use which remains here is to use static attributes/methods of the class that too should be declared in public section. In other terms those static methods/attributesare just another piece of code which you can access in your program. Apart from this you cannot do anything with that class.
I dont know in which situation it would be useful as this particular thing is quite similar to some procedural language technique of having a INCLUDE program with subroutines and some global variables. May be you have to make use of this when you are not at all allowed to use any subroutines in your program.....only classes and methods.
Manish.
Edited by: Manuish on Jan 20, 2012 6:12 PM
‎2012 Jan 24 12:23 PM
Hi,
Abstract class.
An abstract class is used when we want to model an object, the final state of which is not known at the time of modelling and will be known later.
Final Class.
If you don't want anyone else to change or override the functionality of your class then you can define it as final. Thus no one can inherit and modify the features of this class.
‎2012 Jan 25 5:01 AM
hi,
ABSTRACT classes are those in which can't be instantiated and it contains both abstract and non abstract methods .
if we declare the class as abstract then the class should be inherited and we have to implement all the abstract methods of abstract class otherwise that class also should be declared as abstract .
FINAL means the class should not be inherited if we declare the class as final then the class should not be inherited.
so abstract classes can't be final. if we declare the abstract class as final that is meaningless.