Java 2 Final Inheritance and Classes
13) When designing a class hierarchy, it is important that common features be ________________________ . a) higher in the class hierarchy. b) lower in the class hierarchy. c) near the middle of the class hierarchy. d) in abstract classes. e) in the Object class.
a) higher in the class hierarchy.
1) The process of inheritance should establish a(n) ___________________ relationship. a) is-a b) has-a c) static d) not-a e) none of the above
a) is-a
9) A method that has multiple definitions is an __________________ method. a) overloaded b) overridden c) overlooked d) overclocked e) none of the above
a) overloaded
2) Regression testing refers to a) re-testing a program after fixing a problem to ensure that the fix worked and that it did not introduce another problem. b) executing the statements in the program in reverse order. c) executing the program on many different types of computers and comparing the results. d) running a program with many different sets of inputs. e) None of these describes regression testing
a) re-testing a program after fixing a problem to ensure that the fix worked and that it did not introduce another problem.
6) A _______________ variable is shared among all instances of a class. a) static b) final c) public d) private e) none of the above
a) static
15) The versions of an overloaded method are distinguished by ___________________________. a) the number, type and order of their parameters b) their identifiers c) their classes d) the number and type of their parameters e) the number of their parameters
a) the number, type and order of their parameters
3) __________ occurs when a child class defines a method with the same signature as a method in the parent class. a) Overloading b) Overriding c) Overwhelming d) Substituting e) A child class cannot define a method with the same signature as a parent class method.
b) Overriding
1) A ________________ diagram helps us visualize the contents of and relationships among the classes of a program. a) class and object b) UML c) object-oriented d) public e) private
b) UML
11) Which of the following statements is not a general inheritance practice that you should keep in mind in the design of a program? a) Derived classes should have an "is-a" relationship with the parent classes. b) Use the final key word when defining parent classes. c) Avoid shadowing inherited variables when possible. d) Define abstract classes to specify a common class interface for concrete derived classes. e) All of these are general inheritance practices that should be considered when designing a program.
b) Use the final key word when defining parent classes.
7) A(n)______________________ class represents a generic concept in a class hierarchy. a) super b) abstract c) interface d) shadow e) generic
b) abstract
13) A(n) ___________________ object is one that is made up, at least in part, of other objects. a) static b) aggregate c) encapsulated d) private e) public
b) aggregate
8) A class declared as final _________________________________ . a) cannot be changed. b) cannot have subclasses. c) cannot have superclasses. d) has several abstract methods. e) cannot be used in a program.
b) cannot have subclasses.
15) Of the classes below, the one that is most likely to be declared abstract is _________________. a) Bat b) Squirrel c) Animal d) Iguana e) Parrot
c) Animal
7) A(n) __________________ is an application that displays the inner workings of an executing program. a) stethoscope b) telescope c) debugger d) signal analyzer e) oscilloscope
c) debugger
14) If a service is so complex that it cannot be reasonably be implemented using one method, it is often helpful to decompose it to make use of ________________ support methods. a) static b) aggregate c) private d) public e) final
c) private
4) In order for derived classed to have access to encapsulated data members and methods of superclasses, the data members and methods should be declared using the ____________________ modifier. a) private b) public c) protected d) final e) static
c) protected
12) Methods that can be called directly through the class name and do not need to have an object instantiated are called _________________. a) final b) public c) static d) private e) none of the above
c) static
12) All Java classes are subclasses of the ___________________ class. a) String b) java.lang c) Java d) Class e) Object
e) Object
3) When applied to instance variables, the ________________ visibility modifier enforces encapsulation. a) static b) final c) public d) private e) none of the above
d) private
1) A parent class object must be created before objects of a child class can be created.
Answer: False
1) A variable can always be referenced anywhere in a program.
Answer: False
10) Inheritance should not be considered in the software design process.
Answer: False
2) An object can be thought of as a blueprint for a set of classes.
Answer: False
3) Java supports multiple inheritance.
Answer: False
4) Black-box testing uses the internal structure and implementation of the code to be tested in designing the tests.
Answer: False
5) A break point is a statement in a program that causes the program to crash.
Answer: False
7) An abstract class must contain abstract methods.
Answer: False
8) It makes sense to declare most abstract classes as final.
Answer: False
10) Aggregation is sometimes described as a has-a relationship.
Answer: True
2) Private members of a parent class are inherited by child classes.
Answer: True
3) A return statement is not required at the end of every method.
Answer: True
4) In Java, a subclass can only extend one parent class.
Answer: True
5) A child class is allowed to define a method with the same name and parameter list as a method in the parent class.
Answer: True
6) A child class is allowed to declare a variable with the same name as one that is contained in the parent class.
Answer: True
6) A main method can only access static or local variables.
Answer: True
7) In a class that has variables called height and width, methods called getHeight() and getWidth() are examples of accessor methods.
Answer: True
8) Every class has a constructor, whether defined by the programmer or not.
Answer: True
9) It is possible to derive a class from an abstract class without overriding all of the parents abstract methods.
Answer: True
9) Variables that are declared as static are shared among all instances of a class.
Answer: True
9) Which of the following key words indicates a method that cannot be overridden in a derived class? a) super b) final c) extends d) inherits e) expands
b) final
6) When a variable declared in a subclass has the same name as a variable declared in a superclass, it is called a _______________ variable.
b) shadow
14) Which of the following methods are included in every class created in Java by inheritance? a) next b) toString c) compareTo d) charAt e) none of the above
b) toString
10) A(n) ________________ is a step-by-step process for solving a problem. a) UML diagram b) aggregate object c) class d) algorithm e) none of the above
d) algorithm
2) The original class that is used to derive a new class using inheritance is called ____________________ . a) a superclass b) a parent class c) a base class d) all of the above e) neither a, b, nor c
d) all of the above
4) Which of the following types of methods do not have any return type (not even a void return type)? a) methods declared as static b) methods declared as public c) methods declared as private d) constructors e) all of the above have return types
d) constructors
5) Which of the following method headers is most likely a header for a mutator method? a) public int getAge() b) public double computeSalary() c) public Person() d) public void setAge(int newAge) e) none of these are headers for a mutator method
d) public void setAge(int newAge)
10) To invoke a parent's constructor in a subclass, we use the ______________ method. a) abstract b) construct c) parent d) super e) extends
d) super
11) All methods (with the exception of constructors) must specify a return type. What is the return type for a method that does not return any values? a) int b) public c) double d) void e) none of the above
d) void
5) A child class can access private members of a parent class by a) using super in front of the member name b) using the member name directly c) using this in front of the member name d) using the public accessor and mutator methods defined in the parent class e) A child class cannot access private members of a parent class.
e) A child class cannot access private members of a parent class.
8) The ________________ reference always refers to the currently executing object. a) null b) static c) final d) actual e) this
e) this