Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Class Inherit, extend and implement oops

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.

like image 880
Pratik Bhoir Avatar asked Mar 22 '14 05:03

Pratik Bhoir


People also ask

What is the difference between inherits and extends?

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...

What is the difference between extending and implementing?

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.

How do you implement and extend a class in Java?

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.

What is implement in Java?

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.


1 Answers

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).

like image 78
ryrich Avatar answered Sep 30 '22 18:09

ryrich