} }
执行new Dog(“棕熊”);后程序输出是哪项? A. 143 B. 423 C. 243 D. 1134
答案: A
38.public class Pet{ private String name; public Pet(){
System.out.print(1); }
public Pet(String name){ System.out.print(2); } }
public class Dog extends Pet{ public Dog(){
System.out.print(4); }
public Dog(String name){ super(name);
System.out.print(3); } }
执行new Dog(“棕熊”);后程序输出是哪项? A. 33 B. 13 C. 23 D. 123
答案: C
39.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); } }
//下段编译错误
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,SALES B. null,SALES
C. smith,null D. null,null E. 编译错误
答案: A
40.如果想要一个类不能被任何类继承的话,需要使用哪个关键字来修饰该类? A. abstract B. final C. static D. new
答案: B
41.Java语言中常量的定义是哪项? public static A. public static B. public static final C. final
D. public static abstract
答案: B
42.为了使得System.out.println()输出对象引用的时候得到有意义的信息,我们应该覆盖Object中的哪个方法? A. equals B. hashCode C. toString D. notify
答案: C
43.表达式”hello” instanceof String返回的值是哪项? 返回true
A. true B. false C. 1 D. 0 E. hello
答案: A
44.程序: class MyDate{
private int year; private int month; private int day;
public MyDate(int year,int month,int day){
this.year=year;
this.month=month; this.day=day; }
//Override Method }
为了让new MyDate(1980,11,9)==new MyDate(1980,11,9) 返回true,必须在Override Method处覆盖哪个方法?equals A. hashCode B. equals C. toString D. notify
答案: B
45.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
46.public class Pet{
private static String name; public Pet(String name){ this.name = name; }
public static void speak(){ System.out.print(name); } }