Overloading

자바의 한 클래스 내에 이미 사용하려는 이름과 같은 이름을 가진 메소드가 있더라도 매개변수의 개수 또는 타입이 다르면, 같은 이름을 사용해서 메소드를 정의할 수 있다.

같은 이름으로 매개변수에 따라 여러 기능!

overloading을 쓰기보다는 super로 상속받아 속성에 접근하면 부모메소드에 생성자 메소드를 생략해도 된다.

package Day15.Ex03_Employee;

public class Employee {
/*
	public Employee() {
	}
	
	public Employee(String name) {
		this.name = name;
	}
	
	public Employee(String name, String job) {
		this.name = name;
		this.job = job;
	}

	Subclass에서 위 생성자 3개를 대채해줬다.
*/ 
	...
}
///////////////////////////////////////////////////////////

// Subclass
public class Account extends Employee {
	public Account(String name, String job) {
		super.name = name;
		super.job = job;
		// super가 생성자 메소드를 대체한다.
	}
}
///////////////////////////////////////////////////////////

// Subclass2
public class Research extends Employee {
	private String position;
	
	public Research(String name, String position) {
		super.name = name;
		this.position = position;
	}
...
}

Overriding

메소드 오버라이딩은 상속된 메소드의 내용이 자식 클래스에 맞지 않을 경우, 자식 클래서에서 동일한 메소드를 재정의하는 것을 말한다. 메소드가 오버라이딩되었다면 부모 객체의 메소드는 숨겨지기 때문에, 자식 객체에서 메소드를 호출하면 오버라이딩된 자식 메소드가 호출된다.

https://www.geeksforgeeks.org/overriding-in-java/

Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes.

When a method in a subclass has the same name, the same parameters or signature, and the same return type(or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class.

the same name, the same parameters and the same return type!!

Access Modifiers

The access modifier for an overriding method can allow more, but not less, access than the overridden method. For example, a protected instance method in the superclass can be made public, but not private, in the subclass. Doing so will generate a compile-time error.