IT 면접 족보28

권단비·2023년 2월 6일
0

IT

목록 보기
59/139

1. is a 관계와 has a 관계에 대하여 설명하시오.

▼정답

IS-A 관계인지 아리까리하면 HAS-A이다.

[IS-A ex]
사람은 동물이다.
소는 동물이다.
새는 동물이다.

class 동물{}
class 사람 extends 동물{}
class 소 extends 동물{}
class 새 extends 동물{}

-----------------------
[HAS-A ex]
CPU는 컴퓨터이다.(x)
메모리는 컴퓨터이다.(x)

class Computer{
Cpu cpu;
Memory memory;}

2. 다형성(polymorphism)이란 무엇인가?

▼정답

polymorphism(다형성) : 부모는 자식
하나의 객체가 여러 가지 타입을 가질 수 있는 것을 의미

3. 아래가 되지 않는 이유에 대하여 메모리 그림으로 설명하시오.

SmartPhone ph2 = new MobilePhone();

class MobilePhone {
	protected int a; // 전화번호

	public MobilePhone(String a) {
		this.a = a;
	}

	public void answer() {
		System.out.println("Hi~ from " + this.a);
	}
}

class SmartPhone extends MobilePhone {
	private String androidVer; // 안드로이드 운영체제 네임(버전)

	public SmartPhone(String number, String ver) {
		super(number);
		this.androidVer = ver;
	}

	public void playApp() {
		System.out.println("App is running in " + androidVer);
	}
}

▼정답

4. 아래가 되지 않는 이유에 대하여 메모리 그림으로 설명하시오.

MobilePhone ph2 = new SmartPhone("010-999-333", "Nougat");
ph2.playApp();

▼정답

5.다음을 만족하는 클래스 Employee를 작성하시오

(6번문제부터는 이것과 관련된 문제입니다).

- 클래스 Employee(직원)은 클래스 Regular(정규직)와 Temporary(비정규직)의 상위 클래스
- 필드: 이름, 나이, 주소, 부서, 월급 정보를 필드로 선언
- 생성자 : 이름, 나이, 주소, 부서를 지정하는 생성자 정의
- 메소드 printInfo() : 인자는 없고 자신의 필드 이름, 나이, 주소, 부서를 출력 

▼정답

class Employee {
	private String name;
	private int age;
	private String adress;
	private String depart;
	private int pay;

	public Employee(String name, int age, String adress, String depart) {
		this.name = name;
		this.age = age;
		this.adress = adress;
		this.depart = depart;
	}

	public void printInfo() {
		System.out.println(
				"name: " + this.name + "\nage: " + this.age + "\nadress: " + this.adress + "\ndepart: " + this.depart);
	}
}

class Regular extends Employee {
	public Regular(String name, int age, String adress, String depart) {
		super(name, age, adress, depart);
	}
}

class Temporary extends Employee {
	public Temporary(String name, int age, String adress, String depart) {
		super(name, age, adress, depart);
	}
}

public class Test43 {
	public static void main(String[] args) {
		Employee inform = new Employee("아무개", 30, "서울", "IT");
		inform.printInfo();
	}
}

6. 다음을 만족하는 클래스 Regular를 작성하시오.

클래스 Regular는 위에서 구현된 클래스 Employee의 하위 클래스
생성자 : 이름, 나이, 주소, 부서를 지정하는 상위 생성자 호출
Setter : 월급 정보 필드를 지정
메소드 printInfo() : 인자는 없고 "정규직"이라는 정보와 월급을 출력

▼정답

//클래스 Employee(직원)은 클래스 Regular(정규직)와 Temporary(비정규직)의 상위 클래스
//- 필드: 이름, 나이, 주소, 부서, 월급 정보를 필드로 선언
//- 생성자 : 이름, 나이, 주소, 부서를 지정하는 생성자 정의
//- 메소드 printInfo() : 인자는 없고 자신의 필드 이름, 나이, 주소, 부서를 출력 

//클래스 Regular는 위에서 구현된 클래스 Employee의 하위 클래스
//생성자 : 이름, 나이, 주소, 부서를 지정하는 상위 생성자 호출
//Setter : 월급 정보 필드를 지정
//메소드 printInfo() : 인자는 없고 "정규직"이라는 정보와 월급을 출력

class Employee {
	private String name;
	private int age;
	private String adress;
	private String depart;
	protected int pay;

	public Employee(String name, int age, String adress, String depart) {
		this.name = name;
		this.age = age;
		this.adress = adress;
		this.depart = depart;
	}

	public void printInfo() {
		System.out.println(
				"name: " + this.name + "\nage: " + this.age + "\nadress: " + this.adress + "\ndepart: " + this.depart);
	}
}

class Regular extends Employee {
	public Regular(String name, int age, String adress, String depart, int pay) {
		super(name, age, adress, depart);
		super.pay = pay;
	}

	@Override
	public void printInfo() {
		super.printInfo();
		System.out.println("Regular" + " pay: " + super.pay);
	}
}

public class Test43 {
	public static void main(String[] args) {
		Employee inform = new Regular("아무개", 30, "서울", "IT", 1000);
		inform.printInfo();
	}
}
[결과값]
name: 아무개
age: 30
adress: 서울
depart: IT
Regular pay: 1000

0개의 댓글