Write C# programs for Object oriented concepts of C# such as

a. Program using classes

b. Constructor and Function Overloading

c. Inheritance

d. Namespaces

a. Program using classes:-

using System;

namespace practical2

{

    class Customer

    {

        public int custid;

        public string name;

        public string address;

        Customer()

        {

            custid = 1101;

            name = "pinky";

            address = "Thane";

        }

        public void displayData()

        {

            Console.WriteLine("customer=" + custid);

            Console.WriteLine("name=" + name);

            Console.WriteLine("address="+address);

        }

        static void Main(string[] args)

        {

            Customer obj = new Customer();

            obj.displayData();

            Console.WriteLine(obj.custid);

            Console.WriteLine(obj.name);

            Console.WriteLine(obj.address);

            Console.WriteLine("program is exit..........");

            Console.ReadLine();

        }

    }

}

OUTPUT:

Program using classes

b.Constructor and Function Overloading:-

using System;

 

namespace practical2

{

    class showMessage

    {

        public showMessage()

        {

            Console.WriteLine("hi,default message");

        }

        public showMessage(String message)

        {

            Console.WriteLine("message");

        }

        ~showMessage()

        {

            Console.WriteLine("I am destructive and i clean the resource and free up memory as soon as program ends");

        }

    }

    class program

    {

        static void Main(string[] args)

        {

            showMessage sm = new showMessage();

            showMessage sm1 = new showMessage("hi it is constructor");

            Console.WriteLine("Hello World!");

            Console.ReadLine();

        }

    }

}

output:

Constructor and Function Overloading

c. program to implement Inheritance:

using System;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

 

namespaceBasicExample

{

classProgram

    {

staticvoid Main(String[] args)

        {

Scootersc = newScooter();

sc.ScooterType();

 

Car c = newCar();

c.CarType();

Console.ReadKey();

        }

    }

classTyre

    {

protectedvoidTypeTyre()

        {

Console.WriteLine("This is Tubeless Type");

        }

    }

classScooter : Tyre

    {

publicvoidScooterType()

        {

Console.WriteLine("Scooter class is Red");

TypeTyre();

        }

    }

classCar : Tyre

    {

publicvoidCarType()

        {

Console.WriteLine("Car Type:Ferrari");


TypeTyre();

        }

    }

}

OUTPUT:

program to implement Inheritance


ASP.NET PROGRAMS


Post a Comment

0 Comments