单选题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 0B 1C 2D Compilation fails.

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


参考解析

解析: This code is perfectly legal and the answer is C. 

相关考题:

下面代码段的输出结果为( )。 public class Test { public static void main(String sss[]) { int i=0xFFFFFFFl; int j=~i; } }A.0B.1C.14D.-15

阅读和理解下面程序段: class Manager extends Employee{ public Manager(String n,double s,int year,int month,int day){ super(n,s,year,month,day); bonus=0; } public double getSalary(){ double baseSalary-super.gerSalary(); return baseSalary+bonus; } public void setBonus(double b){bonus=b; ) private double bonus; } Manager是Employee的子类,其理由是( )。A.Manager的适用范围较宽B.extends关键字声明C.Manager的域减小了D.雇员是一个经理

已知:Manager extends Employee观察:public Manager(String n,double s,int year,int month,int day) { super(n,s,year,month,day); bonus=0; }其中super是 ( )A.Object类B.Manager类C.Employee类D.Class类

以下程序调试结果为: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.5B.8C.7D.无任何输出E.编译错误

设有类定义如下:class Base{public Base(int i){}}public class MyOver extends Base{public static void main(String arg[]){MyOver m = new MyOver(10);}MyOver(int i){super(i);}MyOver(String s, int i){this(i);//Here}}以下哪条语句可以安排在//Here处 ?A.MyOver m = new MyOver();B.super();C.this("Hello",10);D.Base b = new Base(10);

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、 京巴 DogC、 nullD、 Dog京巴

Which statements concerning the following code are true?()   class a {   public a() {}   public a(int i) { this(); }   }   class b extends a {   public boolean b(String msg) { return false; }   }   class c extends b  {  private c() { super(); }   public c(String msg) { this(); }   public c(int i) {}   }  A、The code will fail to compile.B、The constructor in a that takes an int as an argument will never be called as a result of constructing an  object of class b or c.C、Class c has three constructors.D、Objects of class b cannot be constructed.E、At most one of the constructors of each class is called as a result of constructing an object of class c.

Public class test (  Public static void stringReplace (String text)  (  Text = text.replace (‘j’ , ‘i’);  )  public static void bufferReplace (StringBuffer text)  (  text = text.append (“C”)  )   public static void main (String args[]}  (  String textString = new String (“java”);  StringBuffer text BufferString = new StringBuffer (“java”);  stringReplace (textString);  BufferReplace (textBuffer);  System.out.printLn (textString + textBuffer);  )  )   What is the output?()

class super {  public int getLength()  {return 4;}  }  public class Sub extends Super {  public long getLength() {return 5;}  public static void main (String[]args)  {  super sooper = new Super ();  Sub sub = new Sub();  System.out.printIn(  sooper.getLength()+ “,” + sub.getLength()   };  }  What is the output?()  A、 4, 4B、 4, 5C、 5, 4D、 5, 5E、 The code will not compile.

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、 0B、 1C、 2D、 Compilation fails.

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,SALESB、 null,SALESC、 smith,nullD、 null,null

class super {   public int getLength() {return 4;}    }   public class Sub extends Super {   public long getLength() {return 5;}   public static void main (Stringargs) {   super sooper = new Super ();  Sub sub = new Sub();   System.out.printIn(   sooper.getLength()+ “,” + sub.getLength() };   }   What is the output?() A、 4, 4B、 4, 5C、 5, 4D、 5, 5E、 The code will not compile.

单选题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,SALESB null,SALESC smith,nullD null,nullE 编译错误

单选题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 编译错误

单选题class Super {  public Integer getLenght() { return new Integer(4); } }  public class Sub extends Super {  public Long GetLenght() { return new Long(5); }  public static void main(String[] args) { Super sooper = new Super();  Sub sub = new Sub();  System.out.println(  sooper.getLenght().toString() + “,” +  sub.getLenght().toString() ); } }  What is the output?()A 4,4B 4,5C 5,4D 5,5E Compilation fails.

多选题Which statements concerning the following code are true?()   class a {   public a() {}   public a(int i) { this(); }   }   class b extends a {   public boolean b(String msg) { return false; }   }   class c extends b  {  private c() { super(); }   public c(String msg) { this(); }   public c(int i) {}   }AThe code will fail to compile.BThe constructor in a that takes an int as an argument will never be called as a result of constructing an  object of class b or c.CClass c has three constructors.DObjects of class b cannot be constructed.EAt most one of the constructors of each class is called as a result of constructing an object of class c.

单选题class ClassA {  public int numberOfinstances;  protected ClassA(int numberOfinstances) {  this.numberOflnstances = numberOfinstances;  }  }  public class ExtendedA extends ClassA {  private ExtendedA(int numberOfinstances) {  super(numberOflnstances);  }  public static void main(String[] args) {  ExtendedA ext = new ExtendedA(420);  System.out.print(ext.numberOflnstances);  }  }  Which is true?()A 420 is the output.B An exception is thrown at runtime.C All constructors must be declared public.D Constructors CANNOT use the private modifier.E Constructors CANNOT use the protected modifier.

单选题class super {  public int getLength()  {return 4;}  }  public class Sub extends Super {  public long getLength() {return 5;}  public static void main (String[]args)  {  super sooper = new Super ();  Sub sub = new Sub();  System.out.printIn(  sooper.getLength()+ “,” + sub.getLength()   };  }  What is the output?()A 4, 4B 4, 5C 5, 4D 5, 5E The code will not compile.

单选题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 (straing args) (  sub sub = new sub (“Hello”);   system.out. PrintIn(sub.i);  )   )   What is the result?()A Compilation will fail.B Compilation will succeed and the program will print “0”C Compilation will succeed and the program will print “1”D Compilation will succeed and the program will print “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 京巴 DogC nullD Dog京巴

填空题Public class test (    Public static void stringReplace (String text) (    Text = text.replace („j„ , „i„);    )      public static void bufferReplace (StringBuffer text) (    text = text.append (“C”)   )      public static void main (String args ){  String textString = new String (“java”);    StringBuffer text BufferString = new StringBuffer (“java”);      stringReplace (textString);    BufferReplace (textBuffer);      System.out.printIn (textString + textBuffer);    }   )   What is the output?()

多选题1. class Super {  2. private int a;  3. protected Super(int a) { this.a = a; }  4. }  .....  11. class Sub extends Super {  12. public Sub(int a) { super(a); }  13. public Sub() { this.a= 5; }  14. }  Which two, independently, will allow Sub to compile?()AChange line 2 to: public int a;BChange line 2 to: protected int a;CChange line 13 to: public Sub() { this(5); }DChange line 13 to: public Sub() { super(5); }EChange line 13 to: public Sub() { super(a); }

单选题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,SALESB null,SALESC smith,nullD null,null

单选题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());  }  }   Super的位置是否在方法的首行   执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()A smithB nullC SALESD 编译错误

多选题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;

单选题class Super {  public int getLenght( ) { return 4; }  }  public class Sub extends Super {  public long getLenght( ) { return 5; }  public static void main(String[] args) {  Super sooper = new Super( );  Sub sub = new Sub( );  System.out.println(  sooper.getLenght( ) + “,” + sub.getLenght( ) );  }  } What is the output?()A Just after line 13.B Just after line 14.C Just after line 15.D Just after line 16 (that is, as the method returns).

单选题class super {   public int getLength() {return 4;}    }   public class Sub extends Super {   public long getLength() {return 5;}   public static void main (Stringargs) {   super sooper = new Super ();  Sub sub = new Sub();   System.out.printIn(   sooper.getLength()+ “,” + sub.getLength() };   }   What is the output?()A 4, 4B 4, 5C 5, 4D 5, 5E The code will not compile.