0% found this document useful (0 votes)
22 views

Inheritance

The document contains code for a program that demonstrates inheritance in C#. It defines a base Customer class with properties for ID and name. It then defines a derived RegCustomer class that inherits from Customer and adds a fees property. The Main method creates instances of Customer and RegCustomer, sets their properties, and calls Display methods to output the customers' details.

Uploaded by

Rachit Harlalka
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Inheritance

The document contains code for a program that demonstrates inheritance in C#. It defines a base Customer class with properties for ID and name. It then defines a derived RegCustomer class that inherits from Customer and adds a fees property. The Main method creates instances of Customer and RegCustomer, sets their properties, and calls Display methods to output the customers' details.

Uploaded by

Rachit Harlalka
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

[INHERITANCE] June 13, 2013

Program
using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace Inheritance { class Program { static void Main(string[] args) {

Console.WriteLine("enter id:"); string id = Console.ReadLine(); Console.WriteLine("enter name :"); string name = Console.ReadLine(); Console.WriteLine("enter fees:"); double fee = double.Parse(Console.ReadLine()); RegCustomer reg = new RegCustomer(id, name, fee); reg.Display(); Customer c1 = new Customer("12345", "rachit"); Customer c3 = new Customer("12136", "raghu"); RegCustomer reg1 = new RegCustomer("4364", "sid", 120); reg1.Displays(); c3.Display(); c1.Display(); } } }

Customers
using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace Inheritance { class Customer { string CustId; string CustName; public Customer(string id, string name) { CustId = id;

[INHERITANCE] June 13, 2013


CustName = name; } public void SetCustId(string Id) { CustId = Id; } public string GetCustId() { return CustId; } public void SetCustName(string name) { CustName = name; } public string GetCustName() { return CustName; } public void Display() { Console.WriteLine("customer id is : " + CustId); Console.WriteLine("customer name is :" + CustName); Console.WriteLine("====================="); } } }

Registered_Customers
using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace Inheritance { class RegCustomer:Customer { double fees; public RegCustomer(string id, string name, double fee) : base(id, name) { fees = fee; } public void Displays() { base.Display(); Console.WriteLine("customer fees is : " + fees); } } }

You might also like