Monday, June 7, 2010

Inheritance in C#


using System;


using System.Collections.Generic;


using System.Linq;


using System.Text;


 


namespace Test_in_cs


{


    class publisher


    {


        String title;


        float price;


        public publisher(String t, float p)


        {


            title = t;


            price = p;


        }


        public void displaydata()


        {


            Console.WriteLine("Title: " + title);


            Console.WriteLine("Price: " + price);


        }


    }


    class book : publisher


    {


        int page;


        public book(String t, float p, int c)


            : base(t, p)//Syntax for declaring a derived class.


        {


            page = c;


        }


        public void display()


        {


            base.displaydata();


            Console.WriteLine("Total pages: " + page);


        }


    }


    class Program


    {


        static void Main(string[] args)


        {


            book b = new book("Let us C#", 180.0f, 475);


            b.display();


        }


    }


}

No comments:

Post a Comment