CSCI 2010 QUIZ 1-8 QUESTIONS AND VERIFIED
ANSWERS
Only one constructor may be defined per class. - Answers - False
What is a method? - Answers - A member of a class that defines an operation on an
object.
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? -
Answers - printPage(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? - Answers - Rectangle rect = new Rectangle(8.2, 3.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? - Answers - emp1 refers to the object with the name Anna
Karenina. emp2 refers to the same object.
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? -
Answers - public double computeArea(double length)
When calling a method from another method in the same class, the form methodName()
is equivalent to this.methodName(). - Answers - True
Regular methods may be overloaded, but a constructor may not be overloaded. -
Answers - False
All methods must return a value. - Answers - False
, What is the difference between a static variable and an instance variable? - Answers - A
static variable is shared by all objects of a class. Every object has its own version of an
instance variable.
What is decompostion? - Answers - A design strategy that breaks a task down into
several subtasks.
What is the difference between an accessor method (or getter) and a mutator method
(or setter)? - Answers - An accessor method returns data contained in an instance
variable. A mutator method modifies data contained in an instance variable.
Given the following header for a method in the class Demo:
public static double smallest(double[] data)
Which of the following is the correct way to call this method, given an array of doubles
called values? - Answers - double min = Demo.smallest(values);
Given the following initial array:
{'P', 'A', 'U', 'S'}
Which of the the following correctly illustrates the sequence of passes performed by
selection sort? - Answers - {'P', 'A', 'U', 'S'}
{'A', 'P', 'U', 'S'}
{'A', 'P', 'U', 'S'}
{'A', 'P', 'S', 'U'}
Assume there is a class called Trombone with a default constructor. Which of the
following is the correct way to create and initialize an array of 76 Trombone objects? -
Answers - Trombone[] marchingBand = new Trombone[101];for(int i = 0; i <
marchingBand.length; i++)marchingBand[i] = new Trombone();
Given an array called items, what is the correct way of determining the number of
elements in the array? - Answers - items.length
Which of the following is the correct way to declare an array of 12 integers in Java? -
Answers - int[] numbers = new int[12];
Which of the following is the correct way to initialize a two-dimensional array of integers
with 3 columns and 5 rows? - Answers - int[][] table = new int[5][3];
Given the following class declaration:
public class MyList
ANSWERS
Only one constructor may be defined per class. - Answers - False
What is a method? - Answers - A member of a class that defines an operation on an
object.
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? -
Answers - printPage(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? - Answers - Rectangle rect = new Rectangle(8.2, 3.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? - Answers - emp1 refers to the object with the name Anna
Karenina. emp2 refers to the same object.
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? -
Answers - public double computeArea(double length)
When calling a method from another method in the same class, the form methodName()
is equivalent to this.methodName(). - Answers - True
Regular methods may be overloaded, but a constructor may not be overloaded. -
Answers - False
All methods must return a value. - Answers - False
, What is the difference between a static variable and an instance variable? - Answers - A
static variable is shared by all objects of a class. Every object has its own version of an
instance variable.
What is decompostion? - Answers - A design strategy that breaks a task down into
several subtasks.
What is the difference between an accessor method (or getter) and a mutator method
(or setter)? - Answers - An accessor method returns data contained in an instance
variable. A mutator method modifies data contained in an instance variable.
Given the following header for a method in the class Demo:
public static double smallest(double[] data)
Which of the following is the correct way to call this method, given an array of doubles
called values? - Answers - double min = Demo.smallest(values);
Given the following initial array:
{'P', 'A', 'U', 'S'}
Which of the the following correctly illustrates the sequence of passes performed by
selection sort? - Answers - {'P', 'A', 'U', 'S'}
{'A', 'P', 'U', 'S'}
{'A', 'P', 'U', 'S'}
{'A', 'P', 'S', 'U'}
Assume there is a class called Trombone with a default constructor. Which of the
following is the correct way to create and initialize an array of 76 Trombone objects? -
Answers - Trombone[] marchingBand = new Trombone[101];for(int i = 0; i <
marchingBand.length; i++)marchingBand[i] = new Trombone();
Given an array called items, what is the correct way of determining the number of
elements in the array? - Answers - items.length
Which of the following is the correct way to declare an array of 12 integers in Java? -
Answers - int[] numbers = new int[12];
Which of the following is the correct way to initialize a two-dimensional array of integers
with 3 columns and 5 rows? - Answers - int[][] table = new int[5][3];
Given the following class declaration:
public class MyList