APSU Notes

Quiz 1

Question 1

Only one constructor may be defined per class.


Question 2

What is a method?

A member of a class that defines an operation on an object.

Question 3

A classed called Printer has a method called printDocument. This calls a void method in the Printer class called printPage that takes an integer representing the page number as an argument. How should printDocument call printPage with an argument of 4?


Question 4

Given a class called Rectangle with a constructor that takes two doubles as arguments representing the dimensions, which of the following is the correct way to invoke that constructor?

Rectangle rect = new Rectangle(8.2, 3.5);

Question 5

Consider the following code:

Employee emp1 = new Employee();
emp1.setName("Anna Karenina");
Employee emp2 = new Employee();
emp2.setName("David Copperfield"):
emp2 = emp1;

Which of the following best describes the contents of the two variables emp1 and emp2 after this code has executed?

emp1 refers to the object with the name Anna Karenina. emp2 refers to the same object.

Question 6

Given the following method header:

public double computeArea(double length, double width)

Which of the following would be a legal overloaded method in the same class?

public double computeArea(double length)

Question 7

When calling a method from another method in the same class, the form methodName() is equivalent to this.methodName().


Question 8

Regular methods may be overloaded, but a constructor may not be overloaded.


Question 9

All methods must return a value.


Question 10

What is the difference between a static variable and an instance variable?

A static variable is shared by all objects of a class. Every object has its own version of an instance variable.

Question 11

What is decomposition?

A design strategy that breaks a task down into several subtasks.

Question 12

What is the difference between an accessor method (or getter) and a mutator method (or setter)?**

An accessor method returns data contained in an instance variable. A mutator method modifies data contained in an instance variable.


Chapter 1/Classes and Methods - Review