class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int... nums){   int result=1;   for(int x:nums)   result*=x;   return result;  }  }   程序运行后的输出是哪项?()  A、120B、24C、14D、编译错误

题目

class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int... nums){   int result=1;   for(int x:nums)   result*=x;   return result;  }  }   程序运行后的输出是哪项?()  

  • A、120
  • B、24
  • C、14
  • D、编译错误

相似考题
更多“class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int... nums){   int result=1;   for(int x:nums)   result*=x;   return result;  }  }   程序运行后的输出是哪项?()  A、120B、24C、14D、编译错误”相关问题
  • 第1题:

    有如下程序: public class MethLoad { public static void main(String args[]) { MethLoad classObj = new MethLoad(); classObj.methtest(4); classObj.methtest(4.0); } void methtest(double D) { double sum = 2*d; System.out.println("The result is:"+sum); } void methtest(int n) { int sum = 4*n; System.out.println("The result is:"+sum); } } 程序的运行结果为( )。

    A.The result is:16 The result is:8.0

    B.The result is:8.0 The resuR is:16

    C.The result is:8 The result is:16.0

    D.The resuR is:16.0 The result is:8


    正确答案:A
    解析:本题考查对方法重载的掌握程度。在上面的程序中,类MethLoad中定义了两个具有相同名称methtest的方法,但这两个方法的参数不相同,编译器会根据参数的个数和参数类型宋决定应该调用哪个方法。在类MethLoad中先声明了一个classObj对象,接着调用classObj的methest方法,只不过是两次调用中参数的类型不同,第1次调用的参数是血类型的4,第2次调用的参数是double类型的4.0,因此要调用相对应的方法。int类型的方法返回参数值的4倍,而double类型的方法返回参数值的2倍。

  • 第2题:

    classTestApp{publicstaticvoidmain(String[]args){System.out.println(multiply(2,3,4,5));}publicintmultiply(int…nums){intresult=1;for(intx:nums)result*=x;//result=result*x;returnresult;}}2、6、24、120程序运行后的输出是哪项?()

    A.14

    B.编译错误

    C.120

    D.24


    参考答案:C

  • 第3题:

    interface A{

    int x = 0;

    }

    class B{

    int x =1;

    }

    class C extends B implements A {

    public void pX(){

    System.out.println(x);

    }

    public static void main(String[] args) {

    new C().pX();

    }

    }


    正确答案:

     

    错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的

    x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。

    对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可

    以通过A.x 来明确。

  • 第4题:

    下面的语句片段中,变量result结果为( )。 public class Test { public static void main (String args[ ]) { int sum=0; int r=2; iht result=(sum==1?sum:r); System. out. println (result); } }

    A.1

    B.2

    C.10

    D.0


    正确答案:B
    解析:条件运算符?:为三元运算符,它的一般形式为:expression ? statement1:statement2。其中表达式expression的值应为一个布尔值,若该值为true,则执行语句statement1,否则执行语句statement2,而且语句statement1和statement2需要返回相同的数据类型,且该类型不能是 void。在本题中sum等于0,而不等于1,所以返回r的值为2。

  • 第5题:

    以下程序调试结果为:

    public class Test {

    int m=5;

    public void some(int x) {

    m=x;

    }

    public static void main(String args []) {

    new Demo().some(7);

    }

    }

    class Demo extends Test {

    int m=8;

    public void some(int x) {

    super.some(x);

    System.out.println(m);

    }

    }

    A.5

    B.8

    C.7

    D.无任何输出

    E.编译错误


    正确答案:B

  • 第6题:

    class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int… nums){   int result = 1;   for(int x :nums)   result *= x;  //result =result*x;   return result;  }  }   2、6、24、120   程序运行后的输出是哪项?()  

    • A、 14
    • B、 编译错误
    • C、 120
    • D、 24

    正确答案:C

  • 第7题:

    interface DeclareStuff{  public static final int EASY = 3;  void doStuff(int t); }  public class TestDeclare implements DeclareStuff {  public static void main(String [] args) {  int x=5;  new TestDeclare().doStuff(++x);  }  void doStuff(int s) {  s += EASY + ++s;  System.out.println(”s “ + s);  }  }  What is the result?() 

    • A、 s 14
    • B、 s 16
    • C、 s 10
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:D

  • 第8题:

    public class Yikes {  public static void go(Long n) {System.out.println(”Long “);}  public static void go(Short n) {System.out.println(”Short “);}  public static void go(int n) {System.out.println(”int “);}  public static void main(String [] args) {  short y= 6;  long z= 7;  go(y);  go(z);  }  }  What is the result?() 

    • A、 int Long
    • B、 Short Long
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:A

  • 第9题:

    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()  

    • A、 finished
    • B、 Compilation fails.
    • C、 An AssertionError is thrown.
    • D、 An AssertionError is thrown and finished is output.

    正确答案:A

  • 第10题:

    单选题
    class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int... nums){   int result=1;   for(int x:nums)   result*=x;   return result;  }  }   程序运行后的输出是哪项?()
    A

    120

    B

    24

    C

    14

    D

    编译错误


    正确答案: C
    解析: 暂无解析

  • 第11题:

    单选题
    程序:  class  TestApp{  public static void main(String[] args){  System.out.println(multiply(2,3,4,5));  }  public int multiply(int[] nums){       int result = 1;       for(int x :nums)           result *= x;       return result;   } }  程序运行后的输出是哪项?()
    A

     14

    B

     编译错误

    C

     120

    D

     24


    正确答案: C
    解析: 暂无解析

  • 第12题:

    单选题
    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()
    A

     finished

    B

     Compilation fails.

    C

     An AssertionError is thrown.

    D

     An AssertionError is thrown and finished is output.


    正确答案: D
    解析: This question is a bit tricky because it lacks the following information: It should include a statement that says whether or not assertions are enabled. If they are indeed enabled, the 
    correction answer is C. but if they are not, the correct answer is A. Assertions are not enabled by default so if the question is not changed, the most logical answer is A.

  • 第13题:

    classTestApp{publicstaticvoidmain(String[]args){System.out.println(multiply(2,3,4,5));}publicintmultiply(int...nums){intresult=1;for(intx:nums)result*=x;returnresult;}}程序运行后的输出是哪项?()

    A.120

    B.24

    C.14

    D.编译错误


    参考答案:D

  • 第14题:

    程序:classTestApp{publicstaticvoidmain(String[]args){System.out.println(multiply(2,3,4,5));}publicintmultiply(int[]nums){intresult=1;for(intx:nums)result*=x;returnresult;}}程序运行后的输出是哪项?()

    A.14

    B.编译错误

    C.120

    D.24


    参考答案:C

  • 第15题:

    下列语句中变量result的结果为( )。 public class test { public static void main(String args[ ]) { int sum=10; int r=3; int result=sum %( ++r); System.out.println(result); } }

    A.3

    B.10

    C.2

    D.4


    正确答案:C

  • 第16题:

    有如下程序: public class MethLoad { public static void main(String args[]) { MethLoad classObj=new MethLoad(); classObj.methtest(4); classObj.methtest(0); } void methtest(double d) { double sum=2*d; System.out.println("The result is:"+sum); } void methtest(int n) { int sum=4*n; System.out.println("The result is:" +sum); } }程序的运行结果为( )。

    A.The result is:16 The result is:0

    B.The result is:0 The result is:16

    C.The result is:8 The result is:0

    D.The result is:0 The result is:8


    正确答案:A
    解析:本题考查对方法重载的掌握程度。在上面的程序中,类MethLoad中定义了两个具有相同名称methtest的方法,但这两个方法的参数不相同,编译器会根据参数的个数和参数类型来决定应该调用哪个方法。在类MethLoad中先声明了一个classObi对象,接着调用classObj的methest方法,只不过是两次调用中参数的类型不同,第1次调用的参数是int类型的4,第2次调用的参数是 double类型的0,因此要调用相对应的方法。int类型的方法返回参数值的4倍,而 double类型的方法返回参数值的2倍。

  • 第17题:

    程序:  class  TestApp{  public static void main(String[] args){  System.out.println(multiply(2,3,4,5));  }  public int multiply(int[] nums){       int result = 1;       for(int x :nums)           result *= x;       return result;   } }  程序运行后的输出是哪项?() 

    • A、 14
    • B、 编译错误
    • C、 120
    • D、 24

    正确答案:C

  • 第18题:

    程序:  class TestReference{  public static void main(String[] args){   int x=2;  TestReference tr = new TestReference();          System.out.print(x);          tr.change(x);  System.out.print(x);  }  public void change(int num){      num = num + 1; } }  程序运行后的输出是哪项?()  

    • A、 23
    • B、 21
    • C、 22
    • D、 编译错误

    正确答案:C

  • 第19题:

    public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()  

    • A、 0
    • B、 1
    • C、 2
    • D、 Compilation fails.

    正确答案:D

  • 第20题:

    public class Test {  private static int[] x;  public static void main(String[] args) {  System.out.println(x[0]);  }  }   What is the result?()   

    • A、 0
    • B、 null
    • C、 Compilation fails.
    • D、 A NullPointerException is thrown at runtime.
    • E、 An ArrayIndexOutOfBoundsException is thrown at runtime.

    正确答案:D

  • 第21题:

    单选题
    public class Test {  private static int[] x;  public static void main(String[] args) {  System.out.println(x[0]);  }  }   What is the result?()
    A

     0

    B

     null

    C

     Compilation fails.

    D

     A NullPointerException is thrown at runtime.

    E

     An ArrayIndexOutOfBoundsException is thrown at runtime.


    正确答案: B
    解析: 暂无解析

  • 第22题:

    单选题
    public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()
    A

     0

    B

     1

    C

     2

    D

     Compilation fails.


    正确答案: D
    解析: 暂无解析

  • 第23题:

    单选题
    class TestApp{   public static void main(String[] args){   System.out.println(multiply(2,3,4,5));  }   public int multiply(int… nums){   int result = 1;   for(int x :nums)   result *= x;  //result =result*x;   return result;  }  }   2、6、24、120   程序运行后的输出是哪项?()
    A

     14

    B

     编译错误

    C

     120

    D

     24


    正确答案: C
    解析: 暂无解析