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 13

Chapter 13

Interfaces and Inner Classes

This activity contains 15 questions.

Question 1.
An interface and its methods:


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


Question 2.
An interface may contain:
  1. Concrete methods
  2. Abstract methods
  3. Defined constants
  4. Static variables
  5. Other classes


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


Question 3.
An anonymous class...


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


Question 4.
If a class implements some, but not all, of the methods in an interface, the resulting class is


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


Question 5.
If an inner class extends a different class or implements different interface(s) than does its outer class...


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


Question 6.
If you extend an interface...


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


Question 7.
One of the most frequent uses of inner classes is as a "helper class" in which case:


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


Question 8.
The Serializable and Cloneable interfaces are special because:


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


Question 9.

What can you say about this code?
interface Speaker {
	void speak();
	int age = 3;
}

public class Inherit {

	abstract class Dog implements Speaker {
		protected String name;
	}

	class MyDog extends Dog {
		MyDog() { name = "Lassie"; }
		public void speak() {
			System.out.println(
			  "My name is " + name);
			System.out.println(
			  "My age is " + age);
			}
		}

	Inherit() { new MyDog().speak(); }

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

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


Question 10.

What is printed?
interface Speaker {
	void speak();
}

public class Inherit {

	class Dog implements Speaker {
		public void speak() {
			System.out.println("Woof!");
		}
	}

	class Cat implements Speaker {
		public void speak() {
			System.out.println("Meow!");
		}
	}

	Inherit() {
		Speaker c = new Dog();
		Speaker d = new Cat();
		c.speak();
		d.speak();
	}

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

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


Question 11.

Which statement is true about the following fragment?
  1. A static method could be declared within InnerClass, but not just within OuterClass
  2. A static method could be declared within either InnerClass or within OuterClass
  3. A static method could be declared within InnerClass, but only if InnerClass is declared to be public
  4. A static method can be declared within InnerClass, but only if OuterClass also is declared to be static
public class OuterClass {
    static class InnerClass {

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


Question 12.

Which statement is true?
  1. An outer class may include but a single inner class
  2. An outer class may include several inner classes
  3. An outer class may include several inner classes, but only if they are helper classes
  4. An outer class may include several inner classes, but only if they are all either static or all non-static

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


Question 13.

Which statement is true?
  1. Outer and inner classes have access to each other's public and private members
  2. Outer and inner classes only have access to each other's public members
  3. Outer and inner classes only have access to each other's members if they are declared public or protected
  4. Outer and inner classes do not have access to each other's members

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


Question 14.

Which statement(s) are true? In order to implement an interface, a concrete class must:
  1. include the phrase implements interface_name
  2. provide bodies for all the methods in the interface
  3. provide abstract declarations for any body that is not implemented
  4. cannot inherit from any other class or interface

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


Question 15.

Which statement(s) is (are) true?
  1. It is legal to nest non-static inner classes within non-static inner classes
  2. It is legal to nest static inner classes within non-static inner classes
  3. It is legal to nest non-static inner classes within static inner classes
  4. It is legal to nest static and non-static inner classes within static and non-static inner classes, with the constraint that all the classes be declared public or use package access

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