+ 1
Purpose of Abstract classes?
I get that an abstract class is basically an outline for the other subclasses need to have, such as methods, instance variables, and so on. However, can't we just remove the abstract class and declare the methods directly in the subclasses. It just seems like extra work to me to have an abstract class that does nothing, and when you are setting up the methods and variables in the subclasses anyway. Thanks in advance for the help!
5 Antworten
+ 3
consider 50 classes with same methods, you would have to write every method over and over again. Isin't it just better to write it once and then extend base class? Additionally it helps in Polymorphism (read about it it's really important concept of OOP).
+ 2
@Sathvik No, you don't. If it was Interface you would have to, but not in Abstract Class :)
Edit: Didn't see "abstract method" part. Abstract method indeed have to be overriden in sub classes, but most of the time you won't need them since you've Interfaces where every method is abstract by default ^^
+ 1
Oh thanks. But correct me if i'm wrong, if you create an abstract method in an abstract superclass, don't you have to redefine that method anyway in the sub class?
0
Ok, now it makes sense, thanks @Jakub.
0
If I understand it well, I can't create any instance from the abstract class only other classes can inherit the methods and variables. Practically speaking this is an outline.