执行下面程序,输出的结果是?() public class Test{  public static void main(String[] args){  int a = 5;  double b = 8;  a = a++ + b;   System.out.println(a);  }  } A、 第4行编译报错B、 第5行编译报错C、 编译成功,输出13D、 编译成功,输出14

题目

执行下面程序,输出的结果是?() public class Test{  public static void main(String[] args){  int a = 5;  double b = 8;  a = a++ + b;   System.out.println(a);  }  } 

  • A、 第4行编译报错
  • B、 第5行编译报错
  • C、 编译成功,输出13
  • D、 编译成功,输出14
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

阅读下列代码

Public class Person{

Static int arr[ ] = new int (10);

Public static void main (String args ) {

System.out.println(arr[9]);

}

}

该代码运行的结果是

A )编译时将产生错误

B )编译时正确,运行时将产生错误

C )输出 0

D )输出空


正确答案:C

第2题:

下列代码的执行结果是public class Test{ public int aMethod(){ static int i=0; i++; System.out.println(i); } public static void main(String args[]){ Test test= new Test(); test. aMethod(); }}

A.编译错误

B.0

C.1

D.运行成功,但不输出


正确答案:A
解析:static不能修饰局部变量。

第3题:

执行下面程序,输出的结果是?()publicclassTest{publicstaticvoidmain(String[]args){inta=5;doubleb=8;a=a+++b;System.out.println(a);}}

A.第4行编译报错

B.第5行编译报错

C.编译成功,输出13

D.编译成功,输出14


参考答案:B

第4题:

给出下面的程序: public class ex49 { static int arr[] = new int[10]; public static void main(String args [] ) { System.out.println (art [1] ); } } ______叙述是正确的。

A.编译时将发生错误

B.输出为 null

C.输出为0

D.编译时正确但是运行时出错


正确答案:C

第5题:

对于下面一段代码的描述中,正确的是______。 public class ex36 { public static void run main(String[] args) throws Excepion { method(); } static void method() throws Exception try { System.out.println("test"); } finally { System.out.println ("finally"); } } }

A.代码编译成功,输出“test”和“fmally”

B.代码编译成功,输出“test”

C.代码实现选项A中的功能,之后Java停止程序运行,抛出异常,但是不进行处理

D.代码不能编译


正确答案:A

第6题:

下列程序的执行结果是 ( ) public class Test { public int aMethod() { satic int i=0; i++; System.out.println(i); } public static void.main(String args[]) { Test test=new Test(); test.aMethod(); }

A.编译错误

B.0

C.1

D.运行成功,但不输出


正确答案:A

第7题:

阅读下面代码 public class Person { static int arr[]=new int[10]; public static void main(String args) { System.out.println(arr[9]); } } 该代码的运行结果是

A.编译时将产生错误

B.编译时正确,运行时将产生错误

C.输出零

D.输出空


正确答案:B
解析:Java程序中,main()方法的格式为public staric void main(String args[]) { },返回值为void,参数必须为字符数组。本题目程序的参数不是字符数组,编译不会出错,但是运行时会找不到main()方法,程序无法执行。

第8题:

下面程序段的输出结果是( )。 public class Test { public static void main (String[] args) { for ( int a=0;a<10;a++) { if (a==5) break; System.out.println(A); } } }

A.01234

B.6789

C.012346789

D.5


正确答案:A
解析:题目中输出语句位于循环体内,而在if语句外,所以a5时执行输出语句。当a=5时,退出循环,结束程序的执行。

第9题:

下列代码的执行结果是( )。

public class Test{

public int aMethod( ){

static int i=0;

i++;

System.out.println(i):

}

public static void main (String args[]){

Trest test=new Test ( );

test aMethod( ):

}

}

A.编译错误

B.0

C.1

D.运行成功,但不输出

B.

C.

D.


正确答案:A

第10题:

类A及其派生类B定义如下:class A{ public int getInfo(int a) { return a; }}public class B extends A{ public float getInfo(int b) { return b; } public static void main(String[]args) { A a=new A(); B b=new B(); System.out.println(a.getInfo(3)+","+b.getInfo(5)); }}关于上述程序代码的叙述中正确的是 ( )

A.第10行不能通过编译

B.程序通过编译,输出结果为:3,3

C.程序通过编译,输出结果为3,5

D.程序通过编译,输出结果为:5,5


正确答案:A
解析:本题中,第10不能通过编译,因为getInfo定义的是float型,而里面的参数却是int型,再者,如果定义为float型也不能覆盖classA的方法。所以不正确,应该该为int型。

更多相关问题