以下装箱、拆箱语句中,错误的有()
A: object obj=100; int m=(int)obj;
B: object obj=100; int m=obj;
C: object obj=(int)100; int m=(int)obj;
D: object obj=(object)100; int m=(int)obj;
A: object obj=100; int m=(int)obj;
B: object obj=100; int m=obj;
C: object obj=(int)100; int m=(int)obj;
D: object obj=(object)100; int m=(int)obj;
举一反三
- 执行()程序段之后将出现错误提示。 A: int[]arr={11,21,31}; for(intx:arr) System.out.println(x); B: Object[]obj=newString[]{"111","2222","3333"}; String[]str=(String[])obj; C: Object[]obj={"111","2222","3333"}; String[]str=(String[])obj; D: Object[]arr=newFloat[]{11.1F,22.1F,33.3F,44.44F,55.55F}; for(Floatx:(Float[])arr) System.out.println(x);
- 下面哪个方法不是Object类中定义的方法?( ) A: public boolean equals(Object obj) B: public int compareTo() C: public String toString() D: public int hashCode()
- 若有如下定义,则下列用法中非法的是____ class Objcet{ int x,y; static float f(int a){...} float g(int x1, int x2){...} } Object obj=new Object(); A: Object.g(3,2) B: Object.f(3) C: obj.f(4) D: obj.g(2,5)
- 以下哪项可以实现对象的定义? A: var obj=[]; B: var obj={}; C: var obj=new Object(); D: var obj=123;
- (7-13)请阅读程序,写出程序运行结果。 //运行结果题 public class Demo4 { public static int print(Object obj) { int []arr; int sum=1; if(obj instanceof int[]) { arr=(int[])obj; for(int x:arr) { sum=arr.length+sum; } } return sum; } public static void main(String[] args) { int []arr= {1,2,3,4,5}; String [] list= {"孙悟空","猪八戒","唐僧"}; System.out.println(print(arr)+print(list)); } }