Below is the code for the inheritance example Person class
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace InheritanceExample { class Person { private string name; public Person(string name) { Name = name; } public string Name { get { return name; } set { name = value; } } private int number; public int Number { get { return number; } set { number = value; } } public override string ToString() { return Number.ToString() + ", " + Name; } } }
Employee Class
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace InheritanceExample { class Employee : Person { public Employee(string name): base(name) { } private DateTime hiredate; public DateTime Hiredate { get { return hiredate; } set { hiredate = value; } } private string phoneNumber; public string PhoneNumber { get { return phoneNumber; } set { phoneNumber = value; } } public override string ToString() { string name= base.ToString(); return name + ", " + PhoneNumber + ", " + Hiredate; } } }
Salaried Class
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace InheritanceExample { class Salaried : Employee { double salary; public double Salary { get { return salary; } set { salary = value; } } public override string ToString() { string emp= base.ToString(); return emp + "," + Salary.ToString(); } } }
No comments:
Post a Comment