Home / Java Programming / Declarations and Access Control :: General Questions

Java Programming :: Declarations and Access Control

  1. You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?

  2. A.
    public
    B.
    private
    C.
    protected
    D.
    default access

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What is the widest valid returnType for methodA in line 3?

     public class ReturnIt 
     {   
        returnType methodA(byte x, double y) /* Line 3 */          {         
     return (long)x / y * 2;   
       } 
     } 
    

  4. A.

    int

    B.

    byte

    C.

    long

    D.

    double

    View Answer

    Workspace

    Discuss Discuss in Forum


  5.   class A
      {

      protected int method1(int a, int b)

      {

       return 0;

      }

     }

    Which is valid in a class that extends class A?

     

  6. A.

    public int method1(int a, int b) {return 0; }

    B.

    private int method1(int a, int b) { return 0; }

    C.

    public short method1(int a, int b) { return 0; }

    D.

    static protected int method1(int a, int b) { return 0; }

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. Which one creates an instance of an array?

  8. A.
    int[ ] ia = new int[15];
    B.
    float fa = new float[20];
    C.
    char[ ] ca = "Some String";
    D.
    int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 };

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. Which two of the following are legal declarations for nonnested classes and interfaces?

    1. final abstract class Test {}
    2. public static interface Test {}
    3. final public class Test {}
    4. protected abstract class Test {}
    5. protected interface Test {}
    6. abstract public class Test {}

  10. A.
    1 and 4
    B.
    2 and 5
    C.
    3 and 6
    D.
    4 and 6

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. Which of the following class level (nonlocal) variable declarations will not compile?

  12. A.
    protected int a;
    B.
    transient int b = 3;
    C.
    private synchronized int e;
    D.
    volatile int d;

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. Which two cause a compiler error?

    1. float[ ] f = new float(3);
    2. float f2[ ] = new float[ ];
    3. float[ ]f1 = new float[3];
    4. float f3[ ] = new float[3];
    5. float f5[ ] = {1.0f, 2.0f, 2.0f};

  14. A.
    2, 4
    B.
    3, 5
    C.
    4, 5
    D.
    1, 2

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class?

  16. A.
    final
    B.
    static
    C.
    private
    D.
    protected
    E.
    volatile

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. Which is a valid declaration within an interface?

  18. A.
    public static short stop = 23;
    B.
    protected short stop = 23;
    C.
    transient short stop = 23;
    D.
    final void madness(short stop);

    View Answer

    Workspace

    Discuss Discuss in Forum