Answer the question
In order to leave comments, you need to log in
What is inherited in OOP?
Is the Class itself or its Interface inherited?
Answer the question
In order to leave comments, you need to log in
The class is inherited , the interface is implemented .
interface I {}
class A {}
class B extends A implements I {}
> Is the Class or its Interface inherited?
What does "its interface" mean?
An interface is a separate architectural unit, just like a class. Described by the "interface" keyword.
By default, a class does not have any interface (unless it implements one itself).
---
If a class inherits a class (in Java it is extends), then its methods, fields, properties are inherited. That is, the child class acquires all the members of the base class, and can still add something from itself (or override the inherited class). Methods are inherited along with their implementation, i.e. for the child class, they will work the same way as for the base class.
For example, let's take a GUI: the Button and Label classes inherit the base Control class, while the Left, Top, Width, Height properties inherited from Control work in the same way in both classes. At the same time, the implementation and headers of these methods are written only in Control.
If a class implements an interface (in Java it is implements), then it receives method headers from the interface, and it must implement them itself, and that's all. There are no method implementations in the interface, this is its main difference from the class.
int foo() // - это заголовок метода
{
// а здесь реализация (она же определение, тело...) метода (собственно код)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question