更多"[单选题]下面代码执行结果为()
class A
{
public:
"的相关试题:
[单选题]下列代码的执行结果是
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.运行成功,但不输出
[单选题]下列代码的执行结果是:
public class Test {
public static void main(String[] args) {
int[] x={0,1,2,3};
for(int i=0;i<3;i+=2){
try{
System.out.println(x[i+2]/x[i]+x[i+1]);
}catch(ArithmeticException e){
System.out.println("error1");
}catch(Exception e){
System.out.println("error2");
}
}
}
}
A.error1
B.error2
C.error1
error2
D.2
error2
[单选题] 下列代码的执行结果是: ( )
Public class Test1{
Public static void main(String args[]){
Float t=9.0f;
Int q=5;
System.out.println((t++)*(--q));
}
}
A. 40
B.40.0
C.36
D.36.0
[单选题] 设有如下程序
Public class test {
Public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]);
Int i = intObj.intValue();
If(args.length > 1)
System.out.println(i);
If(args.length > 0)
System.out.println(i - 1);
Else
System.out.println(i - 2);
}
}
运行程序 , 输入如下命令:
Java test 2
则输出为:
A. test
B. test -1
C. 0
D. 1
E. 2
[单选题]下面代码的输出结果是:()
Public class Main {
Public static void main(String[] args) {
Int n1 = 1;
Int n2 = 2;
N1 = n1 + n2;
N2 = n1 - n2;
N1 = n1 - n2;
System.out.println(n1 + "," + n2);
}
}
A. 1,2
B. 2,1
C. 1,3
D. 3,2
[单选题]下列代码的编译或执行结果是:
public class MyVal {
public static void main(String[] args) {
MyVal m = new MyVal();
m.aMethod();
}
public void aMethod(){
boolean [] b = new Boolean [5];
System.out.println(b[0]);
}
}
A.1
B.null
C.0
D.编译错误
[单选题] 以下程序的调试结果为?
class Base{
public final void amethod(){
System.out.println("amethod");
}
}
public class Fin extends Base{
public static void main(String argv[]){
Base b = new Base();
b .amethod();
}
}
A.编译指示带有 final 方法的类自己必须定义为 final
B.编译指示不能继承含有 final 方法的类
C.运行错误,原因是 Base 类没有定义为 final 类
D.运行输出 amethod
[单选题]已知:
class A {
public final void m() {
System.out.println(“A.m”);
}
}
public class B extends A {
public void m() {
System.out.println(“B.m”);
super.m();
}
public static void main(String [] args) {
new B().m();
}
}
那么结果为?
A.A.m
B.B.m
C.B.m
A.m
D.编译错误
[单选题]给出下面代码:
Public class Person{
Static int arr[] = new int[10];
Public static void main(String a[])
{
System.out.println(arr[1]);
}
}
哪个语句是正确的? ( )
A.编译时将产生错误;
B.输出零;
C.编译时正确,运行时将产生错误;
D.输出空。
[单选题]下列代码编译或执行结果的描述中,正确的是:
class Test{
public static void main(String args[]){
TestThread pm1 = new TestThread("One");
pm1.start();
TestThread pm2 = new TestThread("Two");
pm2.start();
}
}
class TestThread extends Thread{
private String sTname="";
TestThread(String s){
sTname = s;
}
public void run(){
for(int i=0;i<2;i++){
try {
sleep(1000);
} catch (InterruptedException e) {}
System.out.println(sTname+" ");
}
}
}
A.不能通过编译,TestThread 类中不能定义变量和构造方法
B.输出One One Two Two
C.输出Two One One Two
D.选项B 或C 都有可能出现
[多选题]设有如下代码:
Class Base{}
Public class MyCast extends Base{
Static boolean b1=false;
Static int i = -1;
Static double d = 10.1;
Public static void main(String argv[]){
MyCast m = new MyCast();
Base b = new Base();
//Here
}
}
则在 //Here 处插入哪个代码将不出现编译和运行错误。
A. b=m;
B. m=b;
C. d =i;
D. b1 =i;
[单选题]下列程序的输出结果是:
public class Test{
public static void main(String[] args){
int [] array={2,4,6,8,10};
int size=6;
int result=-1;
try{
for(int i=0;iA.Catch---1
B.Catch---2
C.Catch---3
D.以上都不对
[单选题] 下列程序运行的结果为:
Public class test {
Public static void main(String args[]) {
Int i;
Float f = 2.3f ;
Double d = 2.7;
I = ((int)Math.ceil(f)) * ((int)Math.round(d));
System.out.println(i);
}
}
A. 4
B. 5
C. 6
D. 6.1
E. 9
[单选题]以下程序的调试结果为?
Public class Outer{
Public String name = "Outer";
Public static void main(String argv[]){
Inner i = new Inner();
I.showName();
}
Private class Inner{
String name =new String("Inner");
Void showName(){
System.out.println(name);
}
}
}
A.输出结果 Outer
B.输出结果 Inner
C.编译错误,因 Inner 类定义为私有访问
D.在创建 Inner 类实例的行出现编译错误
[单选题]阅读下列代码
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.输出空
[单选题] 下面代码完成EditText控件文本的获取,请补全下面的代码?private void submit() { String editTextString = ( ? ) ; }
A.mEditText.getText()
B.mEditText.toString().trim()
C.mEditText.getText().toString().trim()
D.mEditText.toString()
[单选题]下面程序的执行结果是( )。
#include
Void main()
{
Int x=23;
Do{
printf(“%d”,x--);
}while(!x);
}
A.24
B.23
C.22
D.死循环
[单选题] 以下程序调试结果为:
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.编译错误
[单选题]阅读以下代码,输出结果为()
class A
{
public:
virtual void a()=0;
virtual ~A(){}
};
class AA:public A
{
public:
void a()
{
cout<<"nihao 2\n";
}
~AA()
{
cout<<"delete AA \n";
}
};
class AAA:public AA
{
public:
void a()
{
cout<<"nihao 3 \n";
}
~AAA()
{
cout<<"delete AAA \n";
}
};
class B
{
public:
A *b(int kind)
{
if(kind == 1)
return new AA;
else
return new AAA;
}
~B()
{
cout<<"delete B\n";
}
};
int main()
{
B *bb = new B;
A *aa = bb->b(1);
aa->a();
aa = bb->b(2);
aa->a();
delete aa;
delete bb;
return 0;
}
A.
nihao2
nihao3
delete AA
delete AAA
delete B
B.
nihao3
nihao3
delete AAA
delete AA
delete B
C.
nihao2
nihao2
delete AAA
delete AA
delete B
D.
nihao2
nihao3
delete AAA
delete AA
delete B