자바에서 오버로드 메서드를 테스트 할 짧은 프로그램이 있습니다. 이 내 코드입니다 :다른 데이터 유형의 매개 변수로 실행중인 메서드를 오버로드하는 방법은 무엇입니까?
public static void main(String[] args) {
// TODO code application logic here
// Case 1
f2(5);
// Case 2
char x = 'a';
f2(x);
// Case 3
byte y = 0;
f2(y);
// Case 4
float z = 0;
f2(z);
}
그리고 내 방법이 있습니다 :
public static void prt(String s) {
System.err.println(s);
}
public static void f2(short x) {
prt("f3(short)");
}
public static void f2(int x) {
prt("f3(int)");
}
public static void f2(long x) {
prt("f5(long)");
}
public static void f2(float x) {
prt("f5(float)");
}
는 이것은 결과입니다
f3(int)
f3(int)
f3(short)
f5(float)
나는 이해할 수 없다는 어떻게 사건이 실행 않는다 3. 나에 대한 설명이 있나?
정말 고마워요! – Thangnv