inheritance summary
In general, we distinguish two main purposes of using inheritance: we can use it to inherit code (inherit code) and we can use it to inherit type (subtyping). The first is useful for code reuse, the second for polymorphism and specialization.
- When we inherit from concrete classes (“extends”) we do two things: we inherit the implementation and the type.
- When we inherit from interfaces (“implements”) we inherit a type but not the implementation.
- When we inherit from concrete classes ("extend") we do two things: we inherit the implementation and the type. When we inherit from interfaces ("implement") we inherit a type but not the implementation. For cases where both parts are useful we can inherit from abstract classes; here, we inherit the type and a partial implementation.
- When we inherit a complete implementation, we can choose to add or override methods . When no implementation of a type is inherited or a partial implementation of a type is inherited, the subclass must provide the implementation before it can be instantiated.
- Some other object-oriented languages also provide mechanisms for inheriting code without inheriting type. Java does not provide these types of constructs.
What is in bold I can't put the theory into practice, but I have tried the first two sentences.
For cases where both parts are useful we can inherit from abstract classes; here, we inherit the type and a partial implementation.
What happens is that when you inherit from abstract classes, you inherit the methods/behaviors that relate to all of them in common and that is why it refers to partial since it only implements the method that applies to all of them, for example, imagine that the base class of Triangle and circle is the Shape class:
public abstract class Forma { ... public abstract double getArea(); .. }
since the area applies to all members of the form class
When we inherit a complete implementation, we can choose to add or override methods.
What is meant by complete implementation (antonym of partial) means that when you extend a specific class you can override the methods of the class to which you have extended, for example if I have the button class and extend it or I inherit the JButton class, I can inherit all the methods of this, that if @Override were overridden, like this:
When no implementation of a type is inherited or a partial implementation of a type is inherited, the subclass must provide the implementation before it can be instantiated.
Abstract subclasses. For a subclass of an abstract class to become a concrete subclass, it must provide implementations of all inherited abstract methods. Otherwise, it will be properly abstract.
Some other object-oriented languages also provide mechanisms for inheriting code without inheriting type. Java does not provide these types of constructs.
I have no knowledge of that since I only know the Java language
The 3rd point (1st in bold) could be exemplified as follows:
Suppose we have 3 classes:
1- Teacher 2- Student 3- Administrative
The 3 classes can inherit from an abstract Person class that has the attributes and methods that describe it as such and provide it with the correct behavior as Persons.
In this abstract class Person (I don't know if it is syntactically correct in JAVA), from which the other 3 could inherit, there is a GetLegajo() method that returns the ID + last name, it is inherited, and should not be overridden by any of the 3 classes, since its behavior is the same for all.
I think this explains the first point in which you have doubts, I don't understand the rest either :P
I just read THIS , and I think I'm making a mistake in the answer, I recommend you read it, it's in c++ but to understand the concepts the language doesn't matter.