Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
tell me why we use inheritance... not need example just explaning
Posted

This yet another question of the kind "why do we breath?"

Please see:
http://en.wikipedia.org/wiki/Inheritance_%28object-oriented_programming%29[^],
http://en.wikipedia.org/wiki/Override_(object-oriented_programming)[^],
http://en.wikipedia.org/wiki/Interface_inheritance[^],
http://en.wikipedia.org/wiki/Object-oriented_programming[^].

Asking such questions won't help you to lean about programming technology. Instead, you should grab at least on good book on OOP or on .NET and read it all, with good understanding, doing some simple exercises in code while reading. Nothing can replace regular education.

—SA
 
Share this answer
 
Refer

1. [MSDN] When to Use Inheritance[^]
Quote:

Inheritance is a useful programming concept, but it is easy to use inappropriately. Often interfaces do the job better. This topic and When to Use Interfaces help you understand when each approach should be used.

Inheritance is a good choice when:

  • Your inheritance hierarchy represents an "is-a" relationship and not a "has-a" relationship.

  • You can reuse code from the base classes.

  • You need to apply the same class and methods to different data types.

  • The class hierarchy is reasonably shallow, and other developers are not likely to add many more levels.

  • You want to make global changes to derived classes by changing a base class.

These considerations are discussed in order below.


2. Why we need Inheritance in C# or java? Why Inheritance was created in programming?[^]
Quote:
You know the saying...more than one way to skin a cat.

"Need" is a strong word here. Programming is constantly evolving, first off. It's the nature of the game. Programmers try to make life easier through technology. Their own lives, included.

Object Oriented Programming tackles many dilemmas programmers had faced for a long time. Inelegant, spaghetti code with repeated modules everywhere, for example. As said, inheritance is an extremely important concept in OOP, and understanding it will make you a better programmer.

A few reasons though...as to why programmers brought inheritance into the mix:

DRY: Don't Repeat Yourself. It's a concept in programming that speaks about productivity, and readability. Inheritance reduces or eliminates the need for repeated code.

Complexity. OOP reduces the complexity of the code in a program (or at least, it should...). By using inheritance, your code is again, not repeated, and easier to decipher.

Maintenance. In maintaining a solution, inheritance helps out a great deal when implemented correctly.

There is a lot more to the entire OOP paradigm, but understanding the how and why of inheritance is important.
 
Share this answer
 
XML
-Inheritance is a way to form new classes (instances of which are called objects) using classes that have already been defined.
-Inheritance is employed to help reuse existing code with little or no modification.
-The new classes, known as Sub-class or derived class, inherit attributes and behavior of the pre-existing classes, which are referred to as Super-class or Base class.



It is a kind of topic which is not explainable without examples.

please go through this MSDN article..

http://msdn.microsoft.com/en-us/library/27db6csx(v=vs.90).aspx[^]
 
Share this answer
 
Because we think that it's useful.
Because we can group data and behaviour in a reality-imitating fashion.
Because behaviour can belong to a more general, or to a specialized class of items and object orientation along with inheritance allows us to put most things "where they belong".
 
Share this answer
 
Most of us Use inheritance for Updateing Process...Like Releasing Version of software without make changes in old version...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900