网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
单选题
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


参考答案

参考解析
解析: 这个题目涉及继承时的多态性问题,在前面的问题中已经有讲述,要注意的是语句t.print();在运行时t实际指向的是一个Child对象,即java在运行时决定变量的实际类型,而在编译时t是一个Parent对象,因此,如果子类Child中有父类中没有的方法,例如printAll(),那么不能使用t.printAll()。
更多 “单选题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” 相关考题
考题 有如下程序:#includeusing 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 】 。

考题 阅读下列代码 public class Test{ String s="One World One Dream"; public static void main(String args[]){ System. out. println(s); } } 其运行结果是A.argsB.One World One DreamC.sD.编译时出错

考题 在执行下面这段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.nullB.testC.oneD.java

考题 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.

考题 阅读下面代码 public class Test { String s="One World One Dream"; public static void main(String[] args) { System.out.println(s); } } 其运行的结果是A.argsB.World One DreamC.sD.编译时出错

考题 下列语句能给数组赋值而不使用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"};

考题 有如下程序: 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;}执行上面程序的输出是______。

考题 下列代码的输出结果是( )。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;

考题 关于下列代码编译或执行结果的描述中,正确的是( )。 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;i2;i++){ try{ sleep(1000); }catch(InterruptedException e){} system.out.print(sTname+""); } } }A.不能通过编译,TestThread类中不能定义变量和构造方法B.输出One One Two TwoC.输出Two One One TwoD.选项B或C都有可能出现

考题 下列语句能给数组赋值,而不使用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"};

考题 在CardLayout布局管理中,用于显示parent容器的前一张卡片的方法是() A.void previous(Container parent)B.void show(Container parent,String name)C.void next(Container parent)D.void first(Container parent)

考题 class One {  public One() { System.out.print(1); }  }  class Two extends One {  public Two() { System.out.print(2); }  }  class Three extends Two {  public Three() { System.out.print(3); }  }  public class Numbers{  public static void main( String[] argv) { new Three(); }  }  What is the result when this code is executed?() A、 1B、 3C、 123D、 321E、 The code rims with no output.

考题 Which two allow the class Thing to be instantiated using new Thing()?A、 public class Thing { }B、 public class Thing { public Thing() {} }C、 public class Thing { public Thing(void) {} }D、 public class Thing { public Thing(String s) {} }E、 public class Thing { public void Thing() {} public Thing(String s) {} }

考题 现有:  import java.util.*;      class AddStuff2  {  public static void main(String  []  args)  {      TreeSett=new TreeSet();      if (t.add("one"))      if (t.add("two"))     if (t.add ("three"))  add("four");  for (String s  :  t)      System.out.print (s);     }      }      结果为:()     A、 oneB、 one three twoC、 one two threeD、 one two three fourE、 four one three twoF、编译失败

考题 Given the following code:     1) class Parent {     2) private String name;     3) public Parent(){}     4) }  5) public class Child extends Parent {     6) private String department;  7) public Child() {}  8) public String getValue(){ return name; }     9) public static void main(String arg[]) {     10) Parent p = new Parent();     11) }  12) }  Which line will cause error?()   A、 line 3B、 line 6C、 line 7D、 line 8E、 line 10

考题 public class Parent {     int change() {…}     }  class Child extends Parent {     }  Which methods can be added into class Child?()    A、 public int change(){}B、 int chang(int i){}C、 private int change(){}D、 abstract int chang(){}

考题 现有      public class Parentt      public void change (int x){)     )      public class Child extends Parent{     //覆盖父类change方法     }      下列哪个声明是正确的覆盖了父类的change方法?()    A、  protected void change (int x){}B、  public void change(int x,  int y){}C、  public void change (int x){}D、  public void change (String s){}

考题 单选题public class Employee{       private String name;  public Employee(String name){           this.name = name;      }  public String getName(){         return name;      } }  public class Manager extends Employee{       private String department;  public Manager(String name,String department){          this.department = department;          super(name);  System.out.println(getName());      }  }  执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()A  smithB  nullC  SALESD  编译错误

考题 多选题public class Parent {     int change() {…}     }  class Child extends Parent {     }  Which methods can be added into class Child?()Apublic int change(){}Bint chang(int i){}Cprivate int change(){}Dabstract int chang(){}

考题 多选题Which two allow the class Thing to be instantiated using new Thing()?Apublic class Thing { }Bpublic class Thing { public Thing() {} }Cpublic class Thing { public Thing(void) {} }Dpublic class Thing { public Thing(String s) {} }Epublic class Thing { public void Thing() {} public Thing(String s) {} }

考题 单选题public class Parent{     public void change(int x){} }  public class Child extends Parent{     //覆盖父类change方法  }  下列哪个声明是正确的覆盖了父类的change方法?()A  protected void change(int x){}B  public void change(int x, int y){}C  public void change(String s){}D  public void change(int x){}

考题 单选题class One {  public One() { System.out.print(1); }  }  class Two extends One {  public Two() { System.out.print(2); }  }  class Three extends Two {  public Three() { System.out.print(3); }  }  public class Numbers{  public static void main( String[] argv) { new Three(); }  }  What is the result when this code is executed?()A  1B  3C  123D  321E  The code rims with no output.

考题 单选题现有      public class Parentt      public void change (int x){)     )      public class Child extends Parent{     //覆盖父类change方法     }      下列哪个声明是正确的覆盖了父类的change方法?()A   protected void change (int x){}B   public void change(int x,  int y){}C   public void change (int x){}D   public void change (String s){}

考题 单选题Given the following code:     1) class Parent {     2) private String name;     3) public Parent(){}     4) }  5) public class Child extends Parent {     6) private String department;  7) public Child() {}  8) public String getValue(){ return name; }     9) public static void main(String arg[]) {     10) Parent p = new Parent();     11) }  12) }  Which line will cause error?()A  line 3B  line 6C  line 7D  line 8E  line 10

考题 单选题现有:  import java.util.*;      class AddStuff2  {  public static void main(String  []  args)  {      TreeSett=new TreeSet();      if (t.add("one"))      if (t.add("two"))     if (t.add ("three"))  add("four");  for (String s  :  t)      System.out.print (s);     }      }      结果为:()A  oneB  one three twoC  one two threeD  one two three fourE  four one three twoF 编译失败

考题 单选题Given the uncompleted code of a class:     class Person {  String name, department;     int age;  public Person(String n){  name = n; }  public Person(String n, int a){  name = n;  age = a;  }  public Person(String n, String d, int a) {  // doing the same as two arguments version of constructor     // including assignment name=n,age=a    department = d;     }     }  Which expression can be added at the "doing the same as..." part of the constructor?()A  Person(n,a);B  this(Person(n,a));C  this(n,a);D  this(name,age);

考题 单选题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

考题 多选题public class Car {  private int wheelCount;  private String vin;  public Car(String vin) {  this.vin = vin;  this.wheelCount = 4;  }  public String drive() {  return “zoom-zoom”;  }  public String getInfo() {  return “VIN: “+ vin + “wheels: “+ wheelCount;  }  }  And:  public class MeGo extends Car {  public MeGo(String vin) {  this.wheelCount = 3;  }  }  What two must the programmer do to correct the compilation errors?()Ainsert a call to this() in the Car constructorBinsert a call to this() in the MeGo constructorCinsert a call to super() in the MeGo constructorDinsert a call to super(vin) in the MeGo constructorEchange the wheelCount variable in Car to protectedFchange line 3 in the MeGo class to super.wheelCount = 3;