一道东软的程序面试题

来源:百度知道 编辑:UC知道 时间:2024/06/09 02:29:13
public class guahuan{

void test(String i){
System.out.println("An String in!");
}

void test(int i){
System.out.println("An int in!");
}

void test(){
System.out.println("Nothing in!");
}

public static void main(String args[]){
guahuan wx;
wx=new guahuan();
char c = 'a';
wx.test(c);
}
}

结果居然是int 不明白啊

char byte short是比int小的.这3个类型在运算前都会通过编译器自动转换为int.

但是要将int转换为他们的话.就必须显示的转换(就是强转)但可能会丢失数据...因为int比他们大..

char是直接转成asc码的.所以其实也是数字.

char是 0~65535 之间的数字

是重载问题wx.test(c);
是调用void test(int i){
System.out.println("An int in!");
}
这个 方法结果显示An int in!