Learn C# Inheritance by Example

example
In this chapter you will learn inheritance by examples and codes.

Qu : Write a program for creating a Car in which Engine, Tyre, Sound System should be defined in a base class. Your program should inherit all the functionality and gives custom color to a car using interface.

Answer





  • Output

    This is Ferrari
    Engine Type is V.1 4500CC Engine
    Tyre Type is MRF TubeLess Tyre
    Sound System Type is Sony Dolby Digital Extra Bass System
    Car Colour is : SkyBlue

    *********************

    This is BMW
    Engine Type is V.2 5500CC Engine
    Tyre Type is MRF TubeLess Tyre
    Sound System Type is Sony Dolby Digital Extra Bass System
    Car Colour is : Red

    *********************

    This is Ford
    Engine Type is V.2 6500CC Engine
    Tyre Type is MRF TubeLess Tyre
    Sound System Type is Sony Dolby Digital Extra Bass System
    Car Colour is : Coffee
    _

    Summary

    This programing example of inheritance includes real world scenario and their solution. You must practice inheritance in next chapter. Next chapter is Programming Exercise for Inheritance.


    Leave a Reply

    Your email address will not be published. Required fields are marked *