.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Kaviya Balasubramanian
Sgraph Infotech
Imran Ghani

Home >> Interview Question >> .NET Framework >> Post New Question Subscribe to Interview Questions

What is inheritance and when would you use inheritance?

Posted By :Shashi Ray     Posted Date :December 02, 2009    Points :10   Category :.NET Framework 
The concept of child class inheriting the behavior of the parent is called inheritance.

If there are many classes in an application that have some part of their behavior common among all , inheritance would be used.

You can also find related Interview Question to What is inheritance and when would you use inheritance?  below: 

Does C# support multiple inheritance?


C# does not support multiple inheritance. A class can inherit from maximum one base class, although it can implement any number of interfaces. Like Java, C# does not support multiple inheritance, meaning that classes cannot inherit from more than one class (More...)

What is difference between interface inheritance and class inheritance?

We can only inherit from one class but multiple interfaces. In addition, an interface does not contain any implementation it just contains a series of signatures. (More...)

Can you explain what inheritance is and an example of when you might use it?

Inheritance is a fundamental feature of an object oriented system and it is simply the ability to inherit data and functionality from a parent object. Rather than developing new objects from scratch, new code can be based on the work of other programmers, adding only new features that are needed. (More...)

How would you implement inheritance using VB.NET/C#?

When we set out to implement a class using inheritance, we must first start with an existing class from which we will derive our new subclass. This existing class, or base class, may be part of the .NET system class library framework, it may be part of some other application or .NET assembly, or we may create it as part of our existing application. Once we have a base class, we can then implement one or more subclasses based on that base class. Each of our subclasses will automatically have all of the methods, properties, and events of that base class ? including the implementation behind each method, property, and event. Our subclass can add new methods, properties, and events of its own - extending the original interface with new functionality. Additionally, a subclass can replace the methods and properties of the base class with its own new implementation - effectively overriding the original behavior and replacing it with new behaviors. Essentially inheritance is a way of merging functionality from an existing class into our new subclass. Inheritance also defines rules for how these methods, properties, and events can be merged. (More...)

can we impliment multiple inheritance by using interfaces in C#.net?

yes we can implement:

Inheritance Usage Example:
Here is a syntax example for using Implementation Inheritance.

Class derivedClass:baseClass

derivedClass is derived from baseClass.

Interface Inheritance example:
private Class derivedClass:baseClass , InterfaceX , InterfaceY ....


Explain why java doesn't support multiple inheritance.

Java does not support multiple inheritances. To avoid ambiguity problem - Diamonds of Death - and complexity of multiple inheritance.

The Diamond of Death is a problem without clarity. The Diamond problem is:

Two classes Two and Three inherit from class One. Class Four inherits from both Two and Three. When a method in Four invokes a method that is defined in One, and Two and Three have overridden that method in different way, the ambiguity and complexity occurs - through which class does it inherits: class Two or class Three?

Like wise if it is encouraged to have more than two classes to inherit, the ambiguity raises which leads to future conflict of applications. (More...)

Can we implement Multiple Inheritance by using Abstract Class?

As the abstarct class can contain simple methods also, therefore it doesn't support Multiple Inheritance in DotNet. (More...)

does multiple inheritance possible in c#

through interfcae we can do multiple inheritance (More...)

What is implementation inheritance and interface inheritance?

. When a class is derived from another class in such a way that it will inherit all its members to its corresponding derived class, then it is implementation inheritance.

. When a class inherits only the signatures of the functions from its corresponding base class, then it is interface inheritance. (More...)

Advantages of Inheritance

· Once a behavior (method) or property is defined in a super class(base class),that behavior or property is automatically inherited by all subclasses (derived class).

· Code reusability increased through inheritance.

· Inheritance provide a clear model structure which is easy to understand without much complexity Using inheritance, classes become grouped together in a hierarchical tree structure Code are easy to manage and divided into parent and child classes.

Does Csharp support multiple inheritance?

C sharp doenst support multiple inheritance, but can be achived using interface (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend