smith
null
编译错误
name
第1题:
阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。
[说明]
本程序的功能是给公司的员工Tom,Jack,Green增加薪水。三人的职位分别是programmer, Manager,CEO。
程序由6个类组成:WorkerTest是主类,programmer,Manager,CEO三个类,薪水增加的规则是 programmer的涨幅是5%;Manager的是10%;CEO也是Manager,但是它除了有Manager的涨幅,还有1000元的bonus。接口SalaryRaise提供了一个增加薪水的方法raise()。
[java程序]
public class WorkerTest {
public WorkerTest( ) {}
public static void main( String[] args) {
Programmer programmer = new Programmer( "Tom" ,3000);
Manager manager = new Manager( "Jack" ,4000);
CEO ceo = new CEO( "Green" ,4000);
Worker [] worker = new Worker[3];
programmer, raise( );
manager, raise( );
ceo. raise( );
worker[0] = programmer;
worker [1] = manager;
worker[2] = ceo;
for ( int i = 0 ;i < worker, length; i + + ) {
System. out. prinfln (" Name:" + worker [i]. getName ( ) +" \ tSalary:" + worker [i]. getSalary ());
public interface SalaryRaise { void raise( ); }
public class Worker {
public String name;
public double (1);
public Worker( ) {}
public String getName( ) {return name;}
public void setName( String name) {this. name = name;}
public double getSalary( ) {return salary;}
public void setSalary(double salary) { this. salary = salary; }
}
public class Programmer extends Worker implements (2) {
public Programmer( ) {}
public void raise( ) {
double pets=0.05;
double sala = this. getSalary( ) * (1 + pers);
this. setSalary (sala);
public Programmer( Siring name, double salary) t
this. name = name;
this. salary = salary;
public class Manager extends (3) implements SalaryRaise {
public Manager( ) { }
public Manager(String name, double salary) {
this. name = name;
this. salary = salary;
}
public void raise( ) {
double pets = 0.1;
double sala = this. getSalary() * (1 + pers);
this. setSalary(sala);
}
}
public class CEO extends Manager implements SalaryRaise {
public CEO() {}
public CEO( String name,double salary) {
this. name = name;
this. salary = salary;
}
public void raise( ) {
double bonus = 1000;
(4);
double sala = this. getSalary( );
(5);
this. setSalary(sala);
}
}
第2题:
interface Playable {
void play();
}
interface Bounceable {
void play();
}
interface Rollable extends Playable, Bounceable {
Ball ball = new Ball("PingPang");
}
class Ball implements Rollable {
private String name;
public String getName() {
return name;
}
public Ball(String name) {
this.name = name;
}
public void play() {
ball = new Ball("Football");
System.out.println(ball.getName());
}
}
这个错误不容易发现。
错。"interface Rollable extends Playable, Bounceable"没有问题。interface 可继承多个
interfaces,所以这里没错。问题出在interface Rollable 里的"Ball ball = new Ball("PingPang");"。
任何在interface 里声明的interface variable (接口变量,也可称成员变量),默认为public static
final。也就是说"Ball ball = new Ball("PingPang");"实际上是"public static final Ball ball = new
Ball("PingPang");"。在Ball 类的Play()方法中,"ball = new Ball("Football");"改变了ball 的
reference,而这里的ball 来自Rollable interface,Rollable interface 里的ball 是public static final
的,final 的object 是不能被改变reference 的。因此编译器将在"ball = new Ball("Football");"
这里显示有错。
第3题:
为使下列代码正常运行,应该在下划线处填入的选项是
abstract class Person{
public Person(String n)!
name=n;
}
public____String getDescription();
public String getName(){
return name;
}
private String name;
}
A.static
B.private
C.abstract
D.final
第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()); } } Super的位置是否在方法的首行 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
第5题:
执行以下代码后,下面哪些描述是正确的() public class Student{ private String name = “Jema”; public void setName(String name){ this.name = name; } public String getName(){ return this.name; } public static void main(String[] args){ Student s; System.out.println(s.getName()); } }
第6题:
阅读下面代码 abstract class Person { public Person(String n) { name=n; } public______String getDescription(); public String getName() { return name; } private String name; } 在下画线处应填入的修饰符是
A.static
B.abstract
C.protected
D.final
第7题:
为使下列代码正常运行,应该在下画线处填入的选项是( )。 abstract class person{ public Person(String n){ name=n: } Public String getDescription; public String getName{ return name; } private string name; }
A.static
B.private
C.abstract
D.final
第8题:
阅读下列代码段 abstract class Person{ public Person(String n){ name=n; } public______String getDescription(); public String getName(){ } private String name; } 在下画线处应填入的修饰符是
A.static
B.abstract
C.protected
D.final
第9题:
1. public class Employee { 2. String name; 3. double baseSalary; 4. Employee(String name, double baseSalary) { 5. this.name = name; 6. this.baseSalary = baseSalary; 7. } 8. } And: 1. public class Salesperson extends Employee { 2. double commission; 3. public Salesperson(String name, double baseSalary, 4. double commission) { 5. // insert code here 6. } 7. } Which code, inserted at line 7, completes the Salesperson constructor?()
第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(); 后输出的内容是哪项?()