Content Frame
Note for screen reader users: There is text between the form elements on this page. To be sure that you do not miss any text, use item by item navigation methods, rather than tabbing from form element to form element.
Skip Breadcrumb Navigation
Home  arrow Student Resources  arrow Chapter Quizzes  arrow Chapter 5

Chapter 5

Defining Classes II

This activity contains 15 questions.

Question 1.
A "privacy leak" occurs:


Open Hint for Question 1 in a new window.
 
End of Question 1


Question 2.

A copy constructor should:
  • be a constructor with a single argument of the same type as the class
  • create an entirely separate object, with identical data values as in the original object
  • never use the new method (because it causes data leaks)
  • be created when a class contains instance variables that are of non-primitive types

Open Hint for Question 2 in a new window.
 
End of Question 2


Question 3.
How are static variables initialized?


Open Hint for Question 3 in a new window.
 
End of Question 3


Question 4.
Most, but not all, of the wrapper classes are spelled the same as the keyword for the data type that they "wrap," but with an initial capital letter. Which wrappers don't follow this rule?


Open Hint for Question 4 in a new window.
 
End of Question 4


Question 5.
Packages provide:
  • a way to group a collection of classes into a library
  • a way to deal with name clashes
  • a way to override the default CLASSPATH
  • a way to integrate Javadoc-generated output with Javac-generated output


Open Hint for Question 5 in a new window.
 
End of Question 5


Question 6.
What is an immutable class?


Open Hint for Question 6 in a new window.
 
End of Question 6


Question 7.
What is printed?
public class Simple {

	public static void main(String[] args) {
		String str = "-12";
		str += "34";
		float val = 
			Integer.parseInt(str + '5');
		System.out.println("val = " + val);
	}

}


Open Hint for Question 7 in a new window.
 
End of Question 7


Question 8.
What is printed?
public class Simple {

	public static void main(String[] args) {
		Integer num = new Integer(7 + 9);
		double dbl = num.doubleValue() / 2;
		System.out.println("dbl = " + dbl);
	}

}


Open Hint for Question 8 in a new window.
 
End of Question 8


Question 9.

What is printed?
public class Simple {

	Simple() {
		value = (int) (value / 10);
	}

	public String toString() {
		return "" + value;
	}

	public static void main(String[] args) {
		Simple simple = null;
		for (int n = 0; n < 5; n++)
			simple = new Simple();
		System.out.println(simple);
	}

	private static double value = 12345678;
}

Open Hint for Question 9 in a new window.
 
End of Question 9


Question 10.

What is printed?
public class Simple {

	Simple() {
		value = 3;
	}

	void update(Simple s) {
		s.value *= s.value;
	}

	public String toString() {
		return "" + value;
	}

	public static void main(String[] args) {
		Simple s = new Simple();
		Simple t = new Simple();
		s.update(t);
		System.out.println(s + " " + t);
	}

	private short value;
}

Open Hint for Question 10 in a new window.
 
End of Question 10


Question 11.
What is the difference between a deep copy and a shallow copy?


Open Hint for Question 11 in a new window.
 
End of Question 11


Question 12.
When is an object "anonymous?"


Open Hint for Question 12 in a new window.
 
End of Question 12


Question 13.
Which of these short programs correctly reports the number of Blobs that are created?


Open Hint for Question 13 in a new window.
 
End of Question 13


Question 14.
Which of these short programs correctly reports the number of instances of Bleep that are created?


Open Hint for Question 14 in a new window.
 
End of Question 14


Question 15.

Which statement(s) is (are) true?
  • You can invoke a nonstatic method from within a static method
  • You cannot invoke a nonstatic method from within a static method
  • You can invoke a nonstatic method from within a nonstatic method
  • You can invoke a static method from within a static method

Open Hint for Question 15 in a new window.
 
End of Question 15





Pearson Copyright © 1995 - 2010 Pearson Education . All rights reserved. Pearson Addison Wesley is an imprint of Pearson .
Legal Notice | Privacy Policy | Permissions

Return to the Top of this Page