다음 구조의 클래스를 구현하시오.
- 기반 클래스, 파생 클래스의 구조를 설계하고 이를 실행할 수 있는 Main() 메소드가 포함된 콘솔 클래스를 설계한다.
- 기반 클래스명은 Employee로 하고 이를 상속받는 파생 클래스명은 SalesPerson으로 한다.
- 기반 클래스에서 구현하는 필드는 이름, 성별, 나이, 부서고 메소드로는 기반클래스의 속성들을 출력하는 메소드를 구현한다.
- 기반 클래스에서 가상 메소드를 구현한다. 구현할 내용은 “직원입니다.”를 화면에 출력하는 것이다.
- 파생 클래스는 기반 클래스를 상속받으며 가상 메소드를 재정의해서 “영업직원입니다.” 라고 화면에 출력하게 한다.
- 콘솔 클래스에서는 Employee 클래스와 SalesPerson 클래스의 인스턴스를 만들어 각각의 메소드를 실행하는 코드를 구현한다.
[ Soruce ]
using System;
namespace ex1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
///
class Employee // base class
{
protected string eName;
protected string eGender;
protected uint eAge;
protected string eDepart;
public Employee() // constructor
{
eName = "동우석";
eGender = "남성";
eAge = 426;
eDepart = "사장";
}
~Employee() // destructor
{
}
public void cOut()
{
Console.WriteLine("이름 : " + eName);
Console.WriteLine("성별 : " + eGender);
Console.WriteLine("나이 : " + eAge);
Console.WriteLine("부서 : " + eDepart);
}
public virtual void vcOut()
{
Console.WriteLine("본 구성원은 회사의 대표이사입니다..");
}
}
class SalesPerson : Employee // derived class
{
public SalesPerson() // constructor
{
eName = "이수영";
eGender = "여성";
eAge = 27;
eDepart = "영업부";
}
~SalesPerson() // destructor
{
}
public override void vcOut()
{
Console.WriteLine("본 구성원은 영업부의 직원입니다..");
}
}
class cConsole
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
Employee hd_employee = new Employee(); // instance base class
SalesPerson hd_salesman = new SalesPerson(); // instance derived class
Console.WriteLine("========[Base Class Information]=========");
hd_employee.cOut();
hd_employee.vcOut();
Console.WriteLine("========[Derived Class Information]=========");
hd_salesman.cOut();
hd_salesman.vcOut();
}
}
}
댓글
댓글 쓰기