+ 2
Can someone explain abstract classes in easy way?!
for what we use abstract classes?!
2 Answers
+ 2
Before we try abstract classes, first understand that you can make objects using a blueprint we call a class.
If you understand that, abstract classes!!
An abstract class is a class that objects cannot be made from. Abstract classes are typically used as a class from which subclasses can inherit the same variables and methods as the abstract class, allowing users to understand that a particular group of classes all share some of the same methods / variables
For example, you might have an abstract class called "Food". It has variables "age" and "health". Any and all subclasses will inherit these variables. However, you don't actually make items of "Food"; you make items of, say, "Oranges", or "Apples". Any Orange and Apple objects will have variables "age" and "health" in common, as they both inherit it from their superclass, "Food".
Simply put, an abstract class is a reference of what variables and methods any of its subclasses have.
0
Abstract class must contain abstract method, a method that is declared in abstract class but not implemented. Example:
https://code.sololearn.com/csXH885RRZY4/?ref=app