单选题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);    

题目
单选题
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题:

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、 1
  • B、 3
  • C、 123
  • D、 321
  • E、 The code rims with no output.

正确答案:C

第2题:

public class Pet{     private String name;     public Pet(String name){       this.name = name;    }  public void speak(){     System.out.print(name); }  }  public class Dog extends Pet{     public Dog(String name){       super(name);    }  public void speak(){    super.speak();  System.out.print(“ Dog ”);    } }  执行代码   Pet pet = new Dog(“京巴”);  pet.speak();  后输出的内容是哪项?() 

  • A、 京巴
  • B、 京巴 Dog
  • C、 null
  • D、 Dog京巴

正确答案:B

第3题:

阅读下面代码 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

第4题:

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、 smith
  • B、 null
  • C、 SALES
  • D、 编译错误

正确答案:D

第5题:

class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()  

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

正确答案:C

第6题:

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

正确答案:E

第7题:

public class Employee{       private String name;  public Employee(String name){           this.name = name;      }  public void display(){         System.out.print(name);      } }  public class Manager extends Employee{       private String department;  public Manager(String name,String department){          super(name);  this.department = department;  }  public void display(){  System.out.println(super.display()+”,”+department);      } }  执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?() 

  • A、 smith,SALES
  • B、 null,SALES
  • C、 smith,null
  • D、 null,null
  • E、 编译错误

正确答案:E

第8题:

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

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

第9题:

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) {} }

正确答案:A,B

第10题:

public class Employee{   private String name;   public Employee(String name){   this.name = name;  }   public void display(){   System.out.print(name);  }  }   public class Manager extends Employee{   private String department;   public Manager(String name,String department){   super(name);   this.department = department;  }   public void display(){   System.out.println( super.display()+”,”+department);  }   }   执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?() 

  • A、 smith,SALES
  • B、 null,SALES
  • C、 smith,null
  • D、 null,null

正确答案:A

更多相关问题