JAVA中重载方法的调用顺序
发布时间:2020-05-24 11:41:29 所属栏目:Java 来源:互联网
导读:我正在学习一些 java考试,我遇到了这个问题: //Write the output of this program:public static void method(Integer i) { System.out.println(Integer); }public static void method(short i) { System.out.println(short);
|
我正在学习一些 java考试,我遇到了这个问题: //Write the output of this program:
public static void method(Integer i) { System.out.println("Integer"); }
public static void method(short i) { System.out.println("short"); }
public static void method(long i) { System.out.println("long"); }
//...
public static void main(String []args) {
method(10);
}
//ANSWER: long
解释描述了对于整数文字,JVM按以下顺序匹配:int,long,Integer.由于没有带int类型参数的方法,所以查找long类型;等等. 在这个解释中,它们只提供int,long和Integer的顺序. 另外,float,double等的顺序是什么……?(十进制值) 解决方法完整列表可能是int,double,Integer,Number / Comparable / Serializable,Object.注意:Number,Comparable和Serializable是不明确的.选择其中一个将需要一个明确的演员阵容. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
