created 09/24/99 ; revised: 10/04/03


on Encapsulation

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.



1. Why is the main() method special in a Java program?

A.    It is where the Java interpreter starts the whole program running.
B.    Only the main() method may create objects.
C.    Every class must have a main() method.
D.    The main() method must be the only static method in a program.

2. Which of the following is the general scheme for a class definition:

A.   
Class ClassName
{
  // Description of the instance variables.

  // Description of the constructors.

  // Description of the methods.
}
B.   
class ClassName
{
  // Description of the instance variables.

  // Description of the constructors.

  // Description of the methods.
}
C.   
ClassName
{
  // Description of the instance variables.

  // Description of the constructors.

  // Description of the methods.
}
D.   
class ClassName
{
  public static void main ( String[] args )
  {
     // entire program goes here

  }

}

3. Here is the general syntax for method definition:

accessModifier returnType methodName( parameterList )
{
  Java statements

  return returnValue;
}
What is true for the accessModifier?

A.    It must always be private or public.
B.    It can be omitted, but if not omitted it must be private or public.
C.    It can be omitted, but if not omitted there are several choices, including private and public .
D.    The access modifier must agree with the type of the return value.

4. When the access modifier is omitted from the definition of a member of a class (instance variable or method) the member has ..... ?

A.    default access.
B.    public access.
C.    private access.
D.    univeral access.

5. Here is the general syntax for method definition:

accessModifier returnType methodName( parameterList )
{
  Java statements

  return returnValue;
}
What is true for the returnType and the returnValue?

A.    The returnValue must be exactly the same type as the returnType.
B.    The returnValue must be the same type as the returnType, or be of a type that can be converted to returnType without loss of information.
c. The returnValue can be any type, but will be automatically converted to returnType when the method returns to the caller.
d. If the returnType is void then the returnValue can be any type.

6. What term is used for hiding the details of an object from the other parts of a program?

A.    Obfustication.
B.    Data Mining.
C.    Compilation.
D.    Encapsulation.

7. What is the effect of giving a class member private access?

A.    When a member of a class is declared private it can be used in only one place in a program.
B.    When a member of a class is declared private it can be used only in methods that are members of that class.
C.    When a member of a class is declared private it can only be used by other private members of other classes.
D.    When a member of a class is declared private there will be only one instance of it, no matter how many objects are instantiated.

8. Methods of a class that are used by "outsiders" to access private (and other) data of the class are called...

A.    Access methods.
B.    Private methods.
C.    Public methods.
D.    Member methods.

9. What will happen if a main() method of a "testing" class tries to access a private instance variable of an object using dot notation?

A.    The compiler will find the error and will not make a .class file.
B.    The compiler will automatically change the private variable to a public variable.
C.    The program will compile successfully, but the .class file will not run correctly.
D.    The program will compile and run successfully.

The number you got right:       Percent Correct:       Letter Grade:   


Click here

If you have returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the SHIFT KEY while clicking to clear the old answers.