I know this is a stupid question, but still want to know it clearly. The proper difference between Inheriting a class, extending a class, Implementing a class
Please explain with examples.
And if you can provide me a source for a complete detailed oops in c# for studying. Thanks in advance.
Inheritance (noun, not keyword) is a concept. extends (ES6 keyword) is an implementation of that concept. When one class extends another, it inherits its properties...
The keyword extends is used when a class wants to inherit all the properties from another class or an interface that wants to inherit an interface. We use the implements keyword when we want a class to implement an interface.
But you need to declare extends before implements : public class DetailActivity extends AppCompatActivity implements Interface1, Interface2 { // ... } Any number of interfaces can be implemented, if more than one then each needs to be separated with a comma. No Java does not allow that.
Implementations are the data objects used to store collections, which implement the interfaces described in the Interfaces lesson. The Java Collections Framework provides several general-purpose implementations of the core interfaces: For the Set interface, HashSet is the most commonly used implementation.
To clarify what Feisty Mango commented:
Inheriting
refers to the relationship between a derived class (the child) and the base class (the parent). The derived class can use certain methods and fields within the base class according to accessibility levels.
Extending
is interchangeable with Inheriting
and usually is used in java (since the syntax for inheritance in java is the keyword extends
. In C#, it is colon :
Implementing
usually is used with interfaces instead of classes. Mainly because inheriting
or extending
implies parts of classes are being consumed, where with implementing
, it implies the entire interface must be defined by whoever implements it.
Another thing to keep in mind is that you can only extend
or inherit
one class in C#, but can implement multiple interfaces!
Microsoft Docs provides good information related to inheritance (here, among other places).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With