题目内容

下列数组声明语句中,错误的是:

A. int[] arr = new int[8];
B. int[] arr = new int[8]{};
C. int[] arr = {};
D. int[] arr = new int[]{};

查看答案
更多问题

请看下列代码:class Payload {private int weight;public Payload(int wt) { weight = wt; }public Payload() { }public void setWeight(int w) {weight = w;}public String toString() {return Integer.toString(weight);}}public class TestPayload {static void changePayload(Payload p) { 空白处 }public static void main(String[] args) {Payload p = new Payload();p.setWeight(1024);changePayload(p);System.out.println("The value of p is " + p);}}假设运行后输出“The value of p is 420”,那么空白处应填入代码是:

A. p.setWeight(420);
B. Payload.setWeight(420);
C. p = new Payload(420);
D. p = new Payload();p.setWeight(420);

下列代码编译和运行的结果是( )public class Wow {public static void go(short n) { System.out.println("short"); }public static void go(Short n) { System.out.println("SHORT"); }public static void go(Long n) { System.out.println(" LONG"); }public static void main(String[] args) {Short y = 6; int z = 7; go(y); go(z);}}

A. short LONG
B. SHORT LONG
C. 编译失败
D. 抛出运行时异常

请看下列代码public class Foo {public void method(String str,int age){ }}和Foo类中method方法重载的方法是:

A. public int method(String str,int age){}
B. public void method(String s,int year){}
C. public void method(int year,String s){}
D. public int method(int year,String s){}

关于以下 application 的说明,正确的是( )1. class StaticStuff2. {3. static int x=10;4. static { x+=5;}5. public static void main(String args[ ])6. {7.System.out.println(“x=” + x);8. }9. static { x/=3;}10. }

A. 4 行与 9 行不能通过编译,因为缺少方法名和返回类型
B. 9 行不能通过编译,因为只能有一个静态初始化器
C. 编译通过,执行结果为:x=5
D. 编译通过,执行结果为:x=3

答案查题题库