Here is the diagram
Here is the code for the Person class
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Inheritance { class Person { string name; int age; string email; string gender; string address; public string Address { get { return address; } set { address = value; } } public string Gender { get { return gender; } set { gender = value; } } public string Email { get { return email; } set { email = value; } } public int Age { get { return age; } set { age = value; } } public string Name { get { return name; } set { name = value; } } public override string ToString() { return Name + " " + Email; } } }
Here is the Employee class that inherits from Person
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Inheritance { class Employee:Person { int employeeNumber; public int EmployeeNumber { get { return employeeNumber; } set { employeeNumber = value; } } DateTime hireDate; public DateTime HireDate { get { return hireDate; } set { hireDate = value; } } string department; public string Department { get { return department; } set { department = value; } } public override string ToString() { return base.ToString() + " " + Department + " " + hireDate.ToString(); ; } } }
here is the Program file with the main
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Inheritance { class Program { static void Main(string[] args) { DateTime d = new DateTime(1956,5,5); Employee emp = new Employee(); emp.Department = "IT"; emp.Email = "emps@sccd.edu"; emp.Name = "Employee1"; emp.HireDate = d; Console.WriteLine(emp.ToString()); Console.ReadKey(); } } }
No comments:
Post a Comment