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 4

Chapter 4

Defining Classes I

This activity contains 15 questions.

Question 1.
Any method can be used as a void method,


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


Question 2.

Consider the following statements:
  • The attributes that describe an object define the objects state of being.
  • All objects have a state and a set of behaviors.
  • An object is defined by a class.
  • A class by itself is not an object.

Which of these four statements are true?


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


Question 3.
How are local variables are initialized?


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


Question 4.
In order to distinguish among overloaded methods, the compiler uses the method's signature. A signature is composed of:


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


Question 5.
The this keyword:


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


Question 6.
What are the purposes of accessor and mutator methods?


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


Question 7.

What is printed by this program?
public class Tiny {

	int num = 1;

	Tiny() {
		System.out.println("constructor");
		++num;
	}

	void increment() {
		System.out.println("increment");
		while (num < 30)
			num += 10;
	}

	void display() {
		System.out.println("num= " + num);
	}

	public static void main(String[] args) {
		Tiny tiny = new Tiny();
		tiny.increment();
		tiny.display();
		System.out.println();
	}
}

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


Question 8.

What is printed?
public class Arith {

	float a = 3, b = 5, c = 7;

	float value(float a, float b, float c) {
		float d = a + b + 2;
		float e = 3 + b + c;
		return (d * e) / 10.0F;
	}

	Arith() {
		float ans = value(a, b, c);
		System.out.println("ans = " + ans);
	}
		

	public static void main(String[] args) {
		new Arith();
	}
}

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


Question 9.
What is printed?
public class Arith {

	int a = 3, b = 5, c = 7;

	int sum(int a, int b, int c) {
		return (a + b + c);
	}

	Arith() {
		int ans = sum(c, a+b, b);
		System.out.println("ans = " + ans);
	}
		

	public static void main(String[] args) {
		new Arith();
	}
}


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


Question 10.

What is printed?
public class Arith {

	int fcn(int a, int b) {
		return (a * b);
	}

	double fcn(double a, double b) {
		return (b + a);
	}

	Arith() {
		double dA = fcn(4.5, 5.5);
		double dB = fcn(5, 6);
		System.out.println(dB + " " + dA);
	}

	public static void main(String[] args) {
		new Arith();
	}
}

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


Question 11.

What is printed?
public class Arith {

	int fcn(int a, int b) {
		return (a * b);
	}

	int fcn(int a, double b) {
		return (int) (a / b);
	}

	Arith() {
		int ans = fcn(fcn(3, 4), 2.0);
		System.out.println("ans = " + ans);
	}

	public static void main(String[] args) {
		new Arith();
	}
}

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


Question 12.

What is printed?
public class Arith {

	int fcn(int a, int b) {
		return (a * b);
	}

	int fcn(int a, double b) {
		return (int) (a / b);
	}

	public static void main(String[] args) {
		Arith arith = new Arith();
		int vA = arith.fcn(7, 
						   arith.fcn(3, 2));
		int vB = arith.fcn(13, 2.0);
		System.out.println(vA + " " + vB);
	}
}

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


Question 13.

What is printed?
public class Arith {

	int fcn(int a, int b) {
		return (a > b) ? a : b;
	}

	public static void main(String[] args) {
		Arith arith = new Arith();
		int num, ans = 0;
		for (num = 0; num < 10; num += 2)
			ans = arith.fcn(ans, num);

		System.out.println("ans = " + ans);
	}
}
 
End of Question 13


Question 14.

What is printed?
public class Even {

	Even() {
		number = 0;
	}

	Even(final int num) {
		number = 2 * num;
	}

	Even prod(Even evB) {
		return 
			new Even((number*evB.number)/4);
	}

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

	public static void main(String[] args) {
		Even evA = new Even(3);
		Even evB = new Even(7);
		Even evC = evA.prod(evB);
		System.out.println("evC = " + evC);
	}

	private int number;
}

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


Question 15.

Which statement(s) is (are) true?
  • Java programs can have both local and global variables
  • Java programs can have local variables, but global variables are not part of the language
  • Java programs can have global variables, but local variables are not part of the language
  • Java programs can have both local and global variables, so long as their names are spelled differently

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