Abstract class purpose | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Abstract class purpose

Can anyone explain with a basic example what the purpose is of declaring an abstract method in a superclass with no implementation when it is declared and implemented in a subclass that inherits the superclass...why is it even needed?.

17th Jul 2018, 5:55 PM
Steven Moore
Steven Moore - avatar
3 Answers
+ 1
A class "Character" that is not meaningful by itself but gives basic variables like Health can be inherited by other classes to make complex characters that can be instanced. An abstract method could be a Move function that must be custom-made for each character.
20th Jul 2018, 12:15 PM
Lil Taco
Lil Taco - avatar
0
Hi, thanks for the reply but that still doesn't explain the purpose....you type your method in the subclass with its own implementation which I get but that will work exactly the same whether or not you specify an empty abstract method in the superclass...do you follow....what is the difference between specifying the empty method and not specifying it at all?
20th Jul 2018, 5:44 PM
Steven Moore
Steven Moore - avatar
0
so you example of the move function...why bother to write the empty move() method at all...youre going to have to declare it in the subclass anyway if you want to use is so what even is the point of it...can you give me an example of code that either benefits from the empty method...or doesn't work without it.
20th Jul 2018, 6:01 PM
Steven Moore
Steven Moore - avatar