오버라이드
- 자식 클래스에서 부모 클래스의 메서드명과 동일한 메서드를 작성해 사용하는 것
public class Parent {
public void call()
{
System.out.println("Parent 클래스의 CALL method");
}
}
public class Child extends Parent {
public static void main(String[] args) {
Child c= new Child();
c.call(); // Parent 클래스의 CALL method
}
}
오버로드
- 동일한 이름의 메서드를 받는 파라미터만 바꿔서 여러번 작성하는 것
public class Child {
// 오버로드= 동일한 메서드명으로 받는 파라미터를 다르게 해서 작성 가능
public void call()
{
System.out.println("RETURN void");
}
// 오버로드
public void call(String value)
{
System.out.println("RETURN " + value);
}
public static void main(String[] args) {
Child c= new Child();
c.call();
c.call("string");
}
}
'Java' 카테고리의 다른 글
인터페이스, 추상클래스 (0) | 2022.06.25 |
---|---|
this, super (0) | 2022.06.25 |
extends, implements (0) | 2022.06.24 |
List, Set, Map (0) | 2022.06.24 |
배열 선언, 초기화 (0) | 2022.06.24 |