September 2019
Beginner
512 pages
12h 52m
English
In OOP, abstract classes are classes that cannot be instantiated, which makes a lot of sense, depending on the context and the level of abstraction in a program.
For example, our Person class could be abstract if we want to make sure that it only exists in the context of the program if it is a Student instance or another subtype:
abstract class Person { // ... the body was hidden for brevity}
The only thing we need to change here is the beginning of the class definition, marking it as abstract:
main() { Person student = new Student("Clark", "Kent", "Kal-El"); // works as //we are instantiating the subtype // Person p = new Person(); // abstract classes cannot be instantiated print(student); }
As you can see, we can no ...
Read now
Unlock full access