

Next, we can create two more classes and both will be inherited from Phone, Android and iPhone. You can add a new method “Update operating system”. You can also add other fields “screen diagonal”, connectors, and so on. But the behavior of the work will need to be clarified. It no longer needs to redefine the weight and battery, it simply inherits them from the abstract gadget. Let's create a Phone subclass of the Gadget class. While we cannot say what kind of gadget it is, it is absolutely any rechargeable gadget. In this case, methods can be abstract, that is, they do not have a specific implementation. It can have a field (or state) “weight” field battery capacity, field charge level and methods (or behavior) “work” and charging. For example, there is a class called “Gadget”. Often it is denoted as abstract (base class that doesn’t require an implementation). That is, the superclass is the most abstract in the chain of classes. How it worksThe inheritance chain is directed from the most abstract class to the more concrete one.

Simply put, in Java, inheritance means creating new classes based on existing ones.

One such paradigm is inheritance, a mechanism in Java by which one class is allowed to inherit the features (fields and methods) of another class. This means that everything in Java consists of classes and their objects, and obeys the paradigms of OOP (object-oriented programming).
