Java Chapter 8 quiz, Chapter 9 Inheritance, Java Quizzes 10-end, Ch. 10, Chapter 11: Exception Handling
What happens when this is used in a constructor's body to call another constructor of the same class if that call is not the first statement in the constructor?
A compilation error occurs.
Which statement is false?
Clients are usually involved in a class's implementation.
A(n) ______ allows a program to walk through the collection and remove elements from the collection.
Iterator
Which of the following statements about abstract superclasses is true? a. abstract superclasses may contain data. b. abstract superclasses may not contain implementations of methods. c. abstract superclasses must declare all methods as abstract. d. abstract superclasses must declare all data members not given values as abstract.
a. abstract superclasses may contain data.
Assigning a subclass reference to a superclass variable is safe:
because the subclass object is an object of its superclass.
Consider the abstract superclass below: public abstract class Foo { private int a; public int b; public Foo(int aVal, int bVal) { a = aVal; b = bVal; } // end Foo constructor public abstract int calculate(); } //end class foo Any concrete subclass that extends class Foo: a. must implement a method called calculate b. will not be able to access the instance variable a. c. will not be able to instantiate an object of class Foo.
both (a) and (b)
Which of the following is false?
A static method can call instance methods directly.
What is the relationship between superclass and subclass types?
A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.
Which statement is false?
An enum constructor cannot be overloaded.
Instance variables declared final do not or cannot
Be modified after they are initialized.
An advantage of inheritance is that: a. All methods can be inherited. b. All instance variables can be uniformly accessed by subclasses and superclasses. c. Objects of a subclass can be treated like objects of their superclass. d. None of the above.
C. Objects of a subclass can be treated like objects of a superclass.
Collections method sort that accepts a List as an argument sorts the elements of a List, which must implement the ____ interface.
Comparable
If an ObjectInputStream is used to read information from the server, an _____ is generated when the client attempts to read a value from a stream on which end-of-stream is detected.
EOFException
True or False? A non-generic class cannot be derived from a generic class.
False
True or false: UDP is a connection-oriented protocol.
False
______ enables programmers to specify, with a single method declaration, a set of related methods.
Generic methods
When no access modifier is specified for a method or variable, the method or variable:
Has package access.
Having a this reference allows
Having a this reference permits all of these.
A(n) ______ is thrown when a String that is not in proper URL format is passed to a URL constructor
MalformedURLException
Which of the following statements is true?
Methods and instance variables can both be either public or private.
The preferred means of creating multithreaded java applications is by implementing the ____ interface. An object of a class that implements this interface represents a task to perform.
Runnable
Which of the following statements about try blocks is true? a. the try block should contain statements that may throw an exception b. the try block must be followed by a finally block c. the try block should contain statements that may process an exception d. the try block must be followed by at least one catch block.
a. the try block should contain statements that may throw an exception
A(n) _____ class cannot be instantiated.
abstract
A(n) class cannot be instantiated.
abstract
Once the ServerSocket is created, the server can listen indefinitely (or block) for an attempt by a client to connect. This is accomplished with a call to the ServerSocket method ____
accept
BigDecimal gives you control over how values are rounded. By default:
all calculations are exact and no rounding occurs.
What is an uncaught exception?
an exception that occurs for which there are no matching catch clauses.
Which of the following is false? a. A subclass is often larger than its super class. b. A super class is object is a subclass object. c. The class following the extends keyword in a class declaration is that direct super class of the class being declared. d. Java uses interfaces to provide the benefits of multiple inheritance
b. A super class object is a subclass object.
private fields of a superclass can be accessed in a subclass a. by calling private methods declared in the superclass. b. by calling public or protected methods declared in the superclass. c. directly. d. All of the above.
b. By calling public or protected methods in the super class.
Which of the following is the superclass constructor call syntax? a. keyword super, followed by a dot (.) . b. keyword super, followed by a set of parentheses containing the superclass constructor arguments. c. keyword super, followed by a dot and the superclass constructor name. d. None of the above.
b. Keyword super, followed by a set of parentheses containing the superclass constructor arguments.
Every class in Java, except ________, extends an existing class. a. Integer. b. Object. c. String. d. Class.
b. Object
Overriding a method differs from overloading a method because: a. Overloaded methods have the same signature. b. Overridden methods have the same signature. c. Both of the above. d. Neither of the above.
b. Overridden methods have the same signature.
Using the protected keyword also gives a member: a. public access. b. package access. c. private access. d. block scope.
b. Package access
Which of the following is not true of ExecutorService? a. it is a subinterface of executor b. it is an object that can be run in a separate thread. c. it declares method shutdown d. it manages a group of threads
b. it is an object that can be run in a separate thread
Which superclass members are inherited by all subclasses of that superclass? a. private instance variables and methods. b. protected instance variables and methods. c. private constructors. d. protected constructors.
b. protected instance variables and methods.
Which method changes the text the label displays? a. changeText. b. setText. c. changeLabel. d. setLabel.
b. setText
For which of the following would polymorphism not provide a clean solution? a. A billing program where there is a variety of client types that are billed with different fee structures. b. A maintenance log program where data for a variety of types of machines is collected and maintenance schedules are produced for each machine based on the data collected. c. A program to compute a 5% savings account interest for a variety of clients. d. An IRS program that maintains information on a variety of taxpayers and determines who to audit based on criteria for classes of taxpayers.
c. A program to compute a 5% savings account interest for a variety of clients. Because there is only one kind of calculation, there is no need for polymorphism.
Which of the following statements is false? a. A class can directly inherit from class Object. b. It's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires. c. If the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. d. A class's instance variables are normally declared private to enforce good software engineering.
c. If the class you're inheriting from declares instance variables as private the inherited class can access those instance variable directly. (They have to be declared as protected for the inherited class to be able to access them)
Class ________ represents an image that can be displayed on a JLabel. a. Image. b. Icon. c. ImageIcon. d. IconImage.
c. ImageIcon
When overriding a superclass method and calling the superclass version from the subclass method, failure to prefix the superclass method name with the keyword super and a dot (.) in the superclass method call causes ________. a. a compile-time error. b. a syntax error. c. infinite recursion. d. a runtime error.
c. Infinite Recursion
Which of the following is not a superclass/subclass relationship? a. Employee/Hourly Employee. b. Vehicle/Car. c. Sailboat/Tugboat. d. None of the above.
c. Sailboat/Tugboat (they are both different type of boats, they would both be subclasses of superclass boat.)
Classes and methods are declared final for all but the following reasons: a. final methods allow inlining the code. b. final methods and classes prevent further inheritance. c. final methods are static. d. final methods can improve performance.
c. final methods are static.
Which of the following could be used to declare abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)? a. public int method1(); b. public int abstract method1(); c. public abstract int method1(); d. public int nonfinal method1();
c. public abstract int method1();
An interface may contain:
c. public static final data and public abstract methods.
Which statement is false? Normally an applet _____
can read files on any server that can be reached over the network
All exception classes inherit, either directly or indirectly from: ___
class Throwable.
Non-abstract classes are called _____.
concrete classes
Non-abstract classes are called:
concrete classes
Consider the classes below, declared in the same file: class A { int a; public A() { a = 7; } } class B extends A { int b; public B() { b = 8; } } Which of the statements below is false? a. Both variables a and b are instance variables. b. After the constructor for class B executes, the variable a will have the value 7. c. After the constructor for class B executes, the variable b will have the value 8. d. A reference of type A can be treated as a reference of type B.
d. A reference of type A can be treated as a reference of type B.
Which statement best describes the relationship between superclass and subclass types? a. A subclass reference cannot be assigned to a superclass variable and a superclass reference cannot be assigned to a subclass variable. b. A subclass reference can be assigned to a superclass variable and a superclass reference can be assigned to a subclass variable. c. A superclass reference can be assigned to a subclass variable, but a subclass reference cannot be assigned to a superclass variable. d. A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.
d. A subclass reference can be assigned to a superclass variable, but a superclass reference cannot be assigned to a subclass variable.
Which statement is true when a superclass has protected instance variables? a. A subclass object can assign an invalid value to the superclass's instance variables, thus leaving an object in an inconsistent state. b. Subclass methods are more likely to be written so that they depend on the superclass's data implementation. c. We may need to modify all the subclasses of the superclass if the superclass implementation changes. d. All of the above.
d. All of the above are true
Consider the abstract superclass below: public abstract class Foo { private int a; public int b; public Foo( int aVal, int bVal ) { a = aVal; b = bVal; } // end Foo constructor public abstract int calculate(); } // end class Foo Any concrete subclass that extends class Foo: a. Must implement a method called calculate. b. Will not be able to access the instance variable a. c. Neither (a) nor (b). d. Both (a) and (b).
d. Both (a) and (b).
Inheritance is also known as the _______ a. knows-a relationship. b. has-a relationship. c. uses-a relationship. d. is-a relationship.
d. Inheritance is known as the is-a relationship.
Consider classes A, B and C, where A is an abstract superclass, B is a concrete class that inherits from A and C is a concrete class that inherits from B. Class A declares abstract method originalMethod, implemented in class B. Which of the following statements is true of class C? a. Method originalMethod cannot be overridden in class C—once it has been implemented in concrete class B, it is implicitly final. b. Method originalMethod must be overridden in class C, or a syntax error will occur. c. If method originalMethod is not overridden in class C but is called by an object of class C, an error occurs. d. None of the above.
d. None of the above.
The default implementation of method clone of Object performs a ________. a. empty copy. b. deep copy. c. full copy. d. shallow copy.
d. Shallow Copy
When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable? a. A syntax error occurs. b. A compile-time error occurs. c. A run-time error occurs. d. The program compiles and runs because the instance variables are initialized to their default values.
d. The program compiles and runs because the instance variables are initialized to their default values.
Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method? a. base. b. this. c. public. d. super.
d. super (must be called in the default constructor of the subclass)
When the compiler translates a generic method into java bytecodes, it uses _____ to replace the type parameters with actual types.
erasure
Polymorphism allows for specifics to be dealt with during ___
execution
Polymorphism allows for specifics to be dealt with during:
execution
Every object in Java knows its own class and can access this information through method .
getClass
Composition is sometimes referred to as a(n) ________.
has-a relationship
Which keyword is used to specify that a class will define the methods of an interface?
implements
______ sockets and the ______ protocol are more desirable for the vast majority of Java programmers.
Stream, TCP
Which of the following statements is false?
The BigDecimal method format receives a double argument and returns a BigDecimal object that represents the exact value specied.
Which statement is false?
The compiler always creates a default constructor for a class.
Using public set methods helps provide data integrity if:
The instance variables are private AND the methods perform validity checking.
In the catch block below, what is arithmeticException? catch(ArithmeticException arithmeticException){ system.err.print(arithmeticException); }// end catch
The name of catch block's exception parameter
A(n) is thrown when a server address indicated by a client cannot be resolved
UnknownHostException
Which of the following class members should usually be private?
Variables (or fields).
Which of the following statements about abstract superclasses is true? a. abstract superclasses may contain data b. abstract superclasses may not contain implementations of methods c. abstract superclasses must declare all methods as abstract d. abstract superclasses must declare all data members not given values as abstract.
a. abstract superclasses may contain data.
Which method is NOT implicitly final?
a method in an abstract class
Which of the following statements about interfaces is false? a. An interface describes a set of methods that can be called on an object, providing a default implementation for the methods. b. An interface describes a set of methods that can be called on an object, not providing concrete implementation for the methods. c. Interfaces are useful when attempting to assign common functionality to possibly unrelated classes. d. Once a class implements an interface, all objects of that class have an is-a relationship with the interface type.
a. An interface describes a set of methods that can be called on an object, providing a default implementation for the methods.
To avoid duplicating code, use ________, rather than ________. a. inheritance, the "copy-and-past" approach. b. the "copy-and-paste" approach, inheritance. c. a class that explicitly extends Object, a class that does not extend Object. d. a class that does not extend Object, a class that explicitly extends Object.
a. Inheritance, the "copy and paste" approach.
Superclass methods with this level of access cannot be called from subclasses. a. private. b. public. c. protected. d. package.
a. Private level access
The default equals implementation of class Object determines: a. whether two references refer to the same object in memory. b. whether two references have the same type. c. whether two objects have the same instance variables. d. whether two objects have the same instance variable values.
a. Whether two references refer to the same object in memory.
All of the following methods are implicitly final except: a. a method in an abstract class. b. a private method. c. a method declared in a final class. d. static method.
a. a method in an abstract class.
Which syntax imports all static members of class Math?
import static java.lang.Math.*.
If the superclass contains only abstract method declarations, the superclass is used for:
interface inheritance
Declaring a method final means: ___
it cannot be overridden
Declaring a method final means:
it cannot be overridden.
It is a UML convention to denote the name of an abstract class in:
italics
The classes and interfaces which comprise the collections framework are members of package ___
java.util
When a superclass variable refers to a subclass object and a method is called on that object, the proper implementation is determined at execution time. What is the process of determining the correct method to call?
late binding (also called dynamic binding).
The main method executes in the ____ thread of execution
main
Set methods are also commonly called ________ methods and get methods are also commonly called ________ methods.
mutator;accessor
A new thread begins its life cycle by transitioning to the ___ state.
new
A programmer-defined constructor that has no arguments is called a(n) ________.
no-argument constructor.
One generic Stack class could be the basis for creating many Stack classes, e.g., StackMDouble>, Stack<Integer>, and Stack<Employee>. These classes are known as:
parameterized classes
The collections framework algorithms are ___, i.e., each of these algorithms can operate on objects that offer given interfaces without concern to the underlying implementations
polymorphic
Polymorphism enables you to:
program in the general
Polymorphism enables you to:
program in the general.
The _________ of a class are also called the public services or the public interface that the class provides to its clients.
public methods.
When a generic class is instantiated without specifying a type argument, it is said to have a ___
raw type
Using a URL as an argument to the ___ method of interface AppletContext causes the browser in which an applet is executing to display the URL.
showDocument
A constructor cannot:
specify return types or return values.
When a ___ method or block is running on an object, the object is locked so no other such method can run on that object at the same time.
synchronized
To catch an exception, the code that might throw the exception must be enclosed in a ___
try block
A JEditorPane generates HyperlinkEvents ONLY if it is _____
uneditable
Which method returns an array of the enum constants?
values.