Java 에서 method 란, class에 포함되어 있는 함수를 말합니다.
Method overloading 이란, class 내에, 동일한 이름의 method 가 여러가지 있고, 전달되는 인자에 따라 다른 method가 실행 되도록 하는 것을 말합니다.
class A
{
public void functionA()
{
}
public void functionA(int _a)
{
}
public void functionA(int _a, String _b)
{
}
}
Method overriding 이란, 부모 class로 부터 상속 받은 method 를, 자식 class 에서 다시 작성하는 것을 말합니다.
Method overriding 을 하는 2가지 방법이 있습니다.
방법1)
class son 은 class father 로 부터 상속을 받았고, class father 에는 void eat( int _food ) 라는 method를 가지고 있습니다.
class son extends father
{
void eat(String _food) //method overriding
{
}
}
사용시
son _son = new son();
_son.eat("김치");
방법2)
사용하기 전에 즉석으로 overrriding 하는 벙법
father _father = new father()
{
void eat(String _food) //method overriding
{
}
};
_father.eat("김치");
'other_program_languages > java' 카테고리의 다른 글
abstract (추상) class / method (0) | 2020.12.31 |
---|