Review Questions

graphics/rq_icon.gif

4.17

Given the following definition of a class, which fields are accessible from outside the package com.corporation.project?

package com.corporation.project;

public class MyClass {
              int i;
    public    int j;
    protected int k;
    private   int l;
}

Select the two correct answers.

  1. Field i is accessible in all classes in other packages.

  2. Field j is accessible in all classes in other packages.

  3. Field k is accessible in all classes in other packages.

  4. Field k is accessible in subclasses only in other packages.

  5. Field l is accessible in all classes in other packages.

  6. Field l is accessible in subclasses only in other packages.

4.18

How restrictive is the default accessibility compared to public, protected, and private accessibility?

Select the one correct answer.

  1. Less restrictive than public.

  2. More restrictive than public, but less restrictive than protected.

  3. More restrictive than protected, but less restrictive than private.

  4. More restrictive than private.

  5. Less restrictive than protected from within a package, and more restrictive than protected from outside a package.

4.19

Which statement is true about accessibility of members?

Select the one correct answer.

  1. Private members are always accessible from within the same package.

  2. Private members can only be accessed by code from within the class of the member.

  3. A member with default accessibility can be accessed by any subclass of the class in which it is defined.

  4. Private members cannot be accessed at all.

  5. Package/default accessibility for a member can be declared using the keyword default.



     
    ASPTreeView.com
     
    Evaluation has ЙМОУexpired.
    Info...