how do u achieve multilevel inheritance in .NET ?

Answer Posted / raju

C# doesn't support multiple inheritence but multilevel
inheritence is allow here(or by using Abstract classes).So
now u can use the Interface Concepts.Taking an example of
how u can inplement that.

//Abstract class of Animal is define here..
abstract class Animal
{
public void Eat()
{
}
}
//Abstract class of Vechicle is define here..
abstract class Vechicle
{
public void Eat()
{
}
}
//Implementing Interface....
Interface Flyer
{
void Fly();
}


class Aeroplane:Vehicle,Flyer
{
}

class Bird:Animal,Flyer
{
}



As you can see, the two sub classes Bird and Aeroplane
derive from the Animal and Vehicle classes respectively.
Both have the characteristics of their respective base
classes. The Bird like any other animal, eats while the
Aeroplane being a vehicle, runs. However, they both share a
common trait - the ability to fly. This ability is neither
possessed by all animals nor by all vehicles. So it cannot
be defined in either of the base classes. Again, it is not
only possessed by the Aeroplane and Bird, some insects,
baloons and other types of vehicles such as the Helicopter
also possess it. It wouldn’t be effective to define this
ability in each of them. Actually, it will be defined
individually in each of these classes because each have
their own way of flying, the bird flaps the wings, whereas
the helicopter roatates its through a mechanical engine.
However, this ability is declared in the Flyer interface so
that any class which implements this interface would have
to define the Fly() method by overriding it.

Is This Answer Correct ?    15 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is .net mobile input validation. : Microsoft dot net mobile

518


What is a service contract, operation contract and data contract?

524


What is the difference between an event and a delegate?

521


what is sessions and cookies take one example simple way to understand

1843


Explain what does the term "green architecture" mean? : Dot net architecture

546






Explain what does the term "green architecture" mean? : .NET Architecture

518


What happens to the winfx technologies?

571


How do I write to the application configuration file at runtime?

518


Explain hard disk? : Dot net architecture

572


Explain the process of gc?

538


How resource files are used in .net?

540


What is biginteger and when would you use that?

531


Explain the race around condition? : .NET Architecture

504


What is WPF and WCF?

569


Explain the purpose of cache? How is it used? : Dot net architecture

531