Coder Social home page Coder Social logo

shyamkumar-ai-ds / 19ai308-object-oriented-programming-using-csharp--ex7---hierarchical-inheritance Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aswini-j/19ai308-object-oriented-programming-using-csharp--ex7---hierarchical-inheritance

0.0 0.0 0.0 5 KB

C# 100.00%

19ai308-object-oriented-programming-using-csharp--ex7---hierarchical-inheritance's Introduction

Ex7---Hierarchical-Inheritance

AIM:

To write a C# program to implement heirarchical inheritance for the following problem statement: All the vehicles need Tyres on their wheels. So, the manufacturer designs their vehicle as they want and import Tyre from its base class and fit it into Wheels. They don’t need to design Tyre all the time. Once they designed the model and use it various times. Aim is to create a Scooter and Car vehicle where the Tyre is being inherited from vehicle class.

ALGORITHM:

Step 1:

Define a base class 'Vehicle' with a method 'tyre' to describe tyres.

Step 2:

Create a 'Scooter' class inheriting 'Vehicle', with a method 'Display' and 'tyres'.

Step 3:

Implement 'Display' to show class type and call base 'tyre'.

Step 4:

Similarly, make a 'Car' class inheriting 'Vehicle', with a 'Display' method.

Step 5:

Instantiate Car' and 'Scooter', call 'Display' with respective tyre counts.

PROGRAM:

Developed by : Shyam Kumar A
Reg No:   212221230098

using System;
namespace inheritance
{
    class Program
    {
        static void Main(string[] args)
        {
            Scooter scooter = new Scooter();
            Car car = new Car();
        
        
            Console.WriteLine("Scooter started:");
            scooter.display();
        
            Console.WriteLine("\nCar started:");
            car.display();
  
        }
    }
    //Creating Base Class
    public class Vehicle
    {
        public void tyre()
        {
            Console.WriteLine("It is a tubeless tyre");
        }
    }
    //Creating Child Class
    class Scooter : Vehicle
    {
        public void display() 
        {
            base.tyre();
            Console.WriteLine("It is a scooter class");
        }
    }
    //Creating Child Class
    class Car : Vehicle
    {
        public  void display() 
        {
            base.tyre();
            Console.WriteLine("It is a car class");
        }
    }
}

OUTPUT:

image

RESULT:

Thus, the C# program to implement hierarchical inheritance is verified and executed successfully.

19ai308-object-oriented-programming-using-csharp--ex7---hierarchical-inheritance's People

Contributors

shyamkumar-ai-ds avatar aswini-j avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.