created 09/24/99

Quiz on Class Definition

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 a 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.

10. What access modifier explicitly says that a method or variable of an object can be accessed by code outside of the object?

a. private
b. public
c. default
d. static

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

Click here (If you have just 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 on reload to clear the old answers.)