+ 3

Can anyone explain abstract classes?

Howdy! I just recently started learning java, and I'm proud to say that I am getting fond of the language. Until I hit a solid brick wall. Mind teaching me abstract classes, with the most simplest of terms, for I am hollow skulled? Any help is appreciated!😀

29th Jul 2017, 12:26 AM
josef soneja
josef soneja - avatar
2 Antworten
+ 2
The difference between an abstract class is: you cannot create objects from them (instantiate). And you can declare abstract methods. But why do you use it? If you need a class to be a superclass and you don't want anyone create objects from them: simple declare this class as abstract And the abstract methods? if you want a class that extends an abstract class, and be obliged to declare a special method, simple declare this method as abstract inside that abstract class. Example: https://code.sololearn.com/cAi2Vi1kZyG9/?ref=app If you want to read more: https://www.javatpoint.com/abstract-class-in-java
29th Jul 2017, 1:01 AM
Tiago Soares
Tiago Soares - avatar
+ 16
Here's one way to think about it, perhaps. There are three levels of completeness to classes in Java: Interfaces: these define a set of requirements for the classes which implement them. This allows those implementing classes to be used interchangeably, but it provides no base code to work from. Abstract Classes: This is the intermediate step, a class which cannot be instantiated, but it does provide some level of existing code for subclasses to make use of. I've seen these most often in cases where you are trying to link multiple interfaces, and the abstract class provides a translation between them. Concrete Classes: Most common, the only ones on this list which can be instantiated. This is where the rubber meets the road, and the planning involved in the creation of the other types above starts paying off.
29th Jul 2017, 3:05 AM
Jim
Jim - avatar