Nov 08, 2023, 22:25 pm
(This post was last modified: Nov 09, 2023, 00:20 am by RobertX. Edited 2 times in total.)
I have been consulting some texts regarding the purposes of abstracts when used Java.
As I understand it, abstracts are used when different subclasses have different functionalities for the same methods in the superclass.
What would happen if I didn't use abstraction? For example, what would happen if I just use the same name of the methods that are different in behaviour instead of applying such a concept? Wouldn't that be the same thing?
EDIT: To come to think of it, I think I know the answer to my own question: it could be to make the code look clean. If the usperclass has code by default, it could look messy even if overriding it works.
What do you think?
EDIT: Actually, if the abstract methods don't become redefined, I believe the compiler will tell you that. Is the reason that the mechanism of the compiler will remind you, accounting for human error?
As I understand it, abstracts are used when different subclasses have different functionalities for the same methods in the superclass.
What would happen if I didn't use abstraction? For example, what would happen if I just use the same name of the methods that are different in behaviour instead of applying such a concept? Wouldn't that be the same thing?
EDIT: To come to think of it, I think I know the answer to my own question: it could be to make the code look clean. If the usperclass has code by default, it could look messy even if overriding it works.
What do you think?
EDIT: Actually, if the abstract methods don't become redefined, I believe the compiler will tell you that. Is the reason that the mechanism of the compiler will remind you, accounting for human error?