class Parent {     String one, two;  public Parent(String a,

题目
单选题
class Parent {     String one, two;  public Parent(String a, String b){     one = a;     two = b;    }  public void print(){ System.out.println(one); }    }  public class Child extends Parent {     public Child(String a, String b){     super(a,b);     }  public void print(){  System.out.println(one + " to " + two);     }  public static void main(String arg[]){     Parent p = new Parent("south", "north");     Parent t = new Child("east", "west");     p.print();     t.print();     }     }  Which of the following is correct?()
A

 Cause error during compilation. 

B

 south         east 

C

 south to north     east to west    

D

 south to north      east    

E

 south     east to west

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

在执行下面这段Java程序时: public class Test { public static void main (String[] args) { String s1=args[0]; String s2=args[1]; String s3=args[2]; } }若编译程序后键入命令: java Test one two three,那么变量s1所引用的字符串为( )。

A.null

B.test

C.one

D.java


正确答案:C
解析:main()方法中参数表中定义的数组args用于接收命令行参数。在题中提到命令行 java Test one two three中参数分别为"one"、"two"、"three",它们将被依次存放在数组args中。由于在Java中数组的下标从0开始,所以s1所引用的字符串为"one"。

第2题:

阅读下面代码 public class Test { String s="One World One Dream"; public static void main(String[] args) { System.out.println(s); } } 其运行的结果是

A.args

B.World One Dream

C.s

D.编译时出错


正确答案:D

第3题:

有如下程序:

#include

using namespace std;

class PARENT

{

public:

PARENT(){cout<<"PARENT";}

};

class SON:public PARENT

{

public:

SON(){cout<<"SON";}

};

int main()

{

SON son;

PARENT *p;

p = &son;

return 0;

}

执行上面程序的输出是 【 12 】 。


正确答案:

第4题:

关于下列代码编译或执行结果的描述中,正确的是( )。 public class Test{ public static void main(String argsE]){ TcstThread pml=new TestThread("One") pml.start; TestThread pm2=new TestThread("Tw0") pm2.start; } } class TestThread extends Thread( private String sTname=""; TestThread(String s){ sTname=s; } public void run{ for(int i=O;i<2;i++){ try{ sleep(1000); }catch(InterruptedException e){} system.out.print(sTname+""); } } }

A.不能通过编译,TestThread类中不能定义变量和构造方法

B.输出One One Two Two

C.输出Two One One Two

D.选项B或C都有可能出现


正确答案:D
D。【解析】启动两个线程,线程之间没有进行同步,所以B和C均有可能。

第5题:

有如下程序: include using namespace std; class PARENT { public: PARENT() { cout

有如下程序:

include <iostream>

using namespace std;

class PARENT

{

public:

PARENT() { cout <<"PARENT"; }

};

class SON : public PARENT

{

public:

SON() {cout << "SON"; }

};

int main()

{

SON son;

PARENT *p;

p = &son;

return 0;

}

执行上面程序的输出是______。


正确答案:PARENTSON
PARENTSON 解析:此题考查的是派生类的构造。主函数开始在定义SON类的对象son时,会先执行PARENT类的构造函数再执行SON类的构造函数,输出 “PAKENTSON”;接下来的语句定义PARENT和让指针p指向son对象,都并未创建任何对象,所以不会调用构造函数。故最终的输出结果是:PARENTSON。

第6题:

You have recently created a serializable class named Vehicle.The class is shown below:[Serializable]public class Vehicle{public string VIN;public string Make;public string Model;public string Year;}You are planning to create a custom formatter class to control the formatting of Vehicle objects when they are serialized.You need to ensure that is achieved with as little development effort as possible.What should you do?()

A.

B.

C.

D.


参考答案:D

第7题:

下列语句能给数组赋值而不使用for循环的是

A.myArray{[1]="One";[2]="Two";[3]="Three";}

B.String s[5]=new String[]{"Zero", "One", "Two", "There", "Four"};

C.String s[]=new String[]{"Zero", "One", "Two", "There", "Four"};

D.String s[]=new String[]=|"Zero", "One", "Two", "There", "Four"};


正确答案:C
解析:A)、D)语法不正确,B)中s[5]的形式只能通过for循环的格式进行赋值,而不能直接赋值。C)中表达式左侧的“[]”说明现在定义一个数组,不需要指明数组长度,而表达式右侧“[]”在后面直接紧跟初始内容时也是不需要指定数组大小的,数组大小直接由初值长度决定。

第8题:

阅读下列代码 public class Test{ String s="One World One Dream"; public static void main(String args[]){ System. out. println(s); } } 其运行结果是

A.args

B.One World One Dream

C.s

D.编译时出错


正确答案:D
解析:字符串s没有被声明成静态的,题中当主函数调用打印函数输出s的内容时,Test类还没有被实例化,也就没有字符串常量s了。可将字符串s声明为static类型的,或者在打印字符前先实例化Test类,再打印这个对象中的字符串。

第9题:

下列代码的输出结果是( )。

class parent

{

void printme()

{

System.out.println("parent");

}

}

class child extends parent

{

void printme()

{

System. out.println("child");

}

void printall()

{

super, printme();

this.printme();

printme();

}

}

public class test

{

public static void main(String args[])

{

child myc=new child();

myc.printall();

}

}

A.import java.awt.*;

B.import java.applet.applet;

C.import java.io.*;

D.import java, awt.graphics;


正确答案:A

第10题:

下列语句能给数组赋值,而不使用for循环的是

A.myArray{[1]="One";[2]="Two";[3]="Three";}

B.String s[5]=new String[] {"Zero","One","Two","Three","Four"};

C.String s[]=new String[] {"Zero","One","Two","Three","Four"};

D.String s[]=new String[]= {"Zero","One","Two","Three","Four"};


正确答案:C
解析:字符串数组赋初值的方法有两种,一种是如选项C一样初始化。另外一种是先为每个数组元素分配引用空间,再为每个数组元素分配空间并赋初值。例如还可做如下赋值:
  string s[]=new String[5];
  s[0]="Zero";
  s[1]="One";
  s[2]="Two";
  s[3]="Three";
  s[4]="Four";

更多相关问题