Witscale Test Center

Sample test


Sample test

1.    Which of the following statements are true about a static nested class? (Choose all the correct answers)

 

A.      It does not have access to the non-static members of the enclosing class.

B.      Its variables and methods must be declared as static.

C.     There must be an instance of the enclosing class for instantiating the static nested class.

D.     It can be declared in any method of the enclosing class.

E.      A static nested class cannot extend a class and implement an interface at the same time.

F.      A static nested class cannot refer the enclosing class members with this keyword.

 

 

2.    Which of the following statements are true about a member inner class? (Choose all the correct answers)

 

A.      It does not have access to the static members of the enclosing class.

B.      It cannot declare static variables and methods.

C.     There must be an instance of the enclosing class for instantiating the member inner class.

D.     It can be declared in any method of the enclosing class.

E.      A member inner class may extend a class and implement an interface at the same time.

F.      A member inner class can refer the enclosing class members with this keyword.

 

 

3.    Which of the following correctly constructs an instance of an anonymous inner class that implements the following interface?

 

public interface Paddleable {

      void paddle();

}

 

 

A. Paddleable boat = new Paddleable(){ };

B. addBoat(new Paddleable() { public void paddle(){} };);

C. Paddleable boat = new Paddleable(public void paddle() { });

D. Paddleable boat = new Paddleable() { public void paddle{} };

E. Paddleable boat = new Paddleable { public void paddle(){} };

F. addBoat(new Paddleable(public void paddle() {}));

 

4.    Consider the given class declaration.

 

package com.example.cricket;

  abstract class AbstractScoreBoard {

public abstract class LiveScore {

public int getScore() {

return 101;

       }

     }

  }

 

  public class Tester {

    public static void main(String[] args) {

AbstractScoreBoard scoreBoard = new AbstractScoreBoard() {};

AbstractScoreBoard.LiveScore liveScore;

liveScore = scoreBoard.new LiveScore() {

public int getScore() {

              return 51;

}

};

System.out.println(liveScore.getScore());

   }

  }

 

Which of the following is true about the above code?

 

A.      The code will compile and prints 51 after execution.

B.      The code will compile and prints 101 after execution.

C.     The code will compile and prints 0 after execution.

D.     The code fails to compile at line 4 as abstract class AbstractScoreBoard cannot be instantiated.

E.      The code will compile but an exception occurs at runtime.

 

 

5.    Consider the given class declaration. Which of the variables are accessible at line 10? (Choose all the correct answers.)

 

1.    package com.example.photography;

2.      public class Camera {

3.       private float aperture;

4.       public int filmSpeed;

5.       public static String make = "Cannon";

6.     

7.        public void takeAPic(final String mode)

8.         String format = "4x6";

9.         class RoleDeveloper {

10.      void develop(int noOfCopies) {

11.   }

12.  }

13. }

14. 

15.}

 

 

A.      aperture

B.      filmSpeed

C.      make

D.     mode

E.      format

F.       noOfCopies

 

 

6.    Which of the following statements are true? (Choose all the correct answers.)

 

A.      An anonymous inner class inside a class Outer implements the ActionListener interface. This anonymous class can be instantiated as

new Outer().new ActionListener();

B.      A non-static member inner class is declared inside class Outer. It may be instantiated as:

new Outer().new Inner();

C.      A non-static member inner class Inner is declared inside class Outer. It may be instantiated as:

Outer.new Inner();

D.     A static nested class Inner defined inside a class Outer may be instantiated as:

new Outer().new Inner();

E.      A static nested class Inner defined inside a class Outer may be instantiated as:

Outer.new Inner();