试题

I. Examine the following statements and indicate whether it is true or false:

  1. All methods in an abstract superclass must be declared abstract.
    Chapter 3.3

  2. A class declared final cannot be subclassed. Every method of a final class is implicitly final.

  3. A redefinition of a superclass method in a subclass need not have the same signature as the superclass method. Such a redefinition is not method overriding but is simply an example of method overloading.
    Chapter 2

  4. A constructor is a special method with the same name as the class that is used to initialize the members of a class object. Constructors are called when objects of their classes are instantiated.

  5. A method declared static cannot access nonstatic class members. A static method has not this reference because static class variables and static methods exist independent of any objects of a class.

  6. An array subscript may be an integer or an integer expression. If a program uses an expression as a subscript, then the expression is evaluated to determine the particular element of the array.
    Chapter 2.2

  7. To pass one row of a double-subscripted array to a method that receives a single-subscripted array, simply pass the name of the array followed by the row subscript.
    Chapter 2.2

  8. Overloaded methods can have different return values, and must have different parameter lists. Two methods differing only by return type will result in a compilation error.
    Chapter 2

  9. The applet’s paint method is called after the init method completes execution and the start method has started executing to draw on the applet. It is also called automatically every time the applet needs to be repainted.
    Chapter 9

  10. Any block of Java code may contain variable declarations.

II. Multiple choice. There’s only one correct choice for each problem.

  1. Given:
    public class AnimalHouse {
    private E animal;
    public void setAnimal(E x) {
    animal = x;
    }
    public E getAnimal() {
    return animal;
    }
    }
    public class Animal{}
    public class Cat extends Animal {}
    public class Dog extends Animal {}
    Which statement below compiles?
    A.AnimalHouse house = new AnimalHouse();
    B.AnimalHouse house = new AnimalHouse();
    C.AnimalHouse<?> house = new AnimalHouse(); house.setAnimal(new Cat());
    D.AnimalHouse house = new AnimalHouse(); house.setAnimal(new Dog());

Chapter 4.2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值