Final Exam (M7-M11) (Part II)

Ace your homework & exams now with Quizwiz!

A public static method can be referenced from another class by using the class name and the dot notation. a. True b. False

a

An Exception is an object that describes an unusual or erroneous situation. a. True b. False

a

An input/output (I/O) stream is a sequence of bytes that flow from a source to a destination. a. True b. False

a

If an expression that includes integer division by zero (e.g., 10 / 0) is evaluated, an exception is thrown (i.e., run-time error occurs). a. True b. False

a

If you wanted to sort items in an order other than their natural ordering, the Comparator interface in the Java API should be implemented. a. True b. False

a

Suppose parent class P has a child class C (i.e., C extends P), and we have the following assignment of a child C object to a reference of the parent type P: P p = new C( ); Then any method defined in the parent class P can be called on p without casting. a. True b. False

a

The protected access modifier can be applied to the fields of a class to allow subclasses and classes in the same package direct access to the fields. a. True b. False

a

When a method is declared as private, it can be accessed within the class, but it cannot be accessed from outside the class. a. True b. False

a

When an exception occurs the call stack trace that shows the methods that were invoked along the path to the where the exception occurred. a. True b. false

a

A reference variable of type C can refer to an object of class C or to an object of any subclass of C, as well as any object the parent of C. a. True b. False

b

If a checked exception is not caught or listed in the throws clause and you attempt to compile and/or execute the program, a run-time error occurs? a. True b. False

b

In object-oriented programming, a class can be considered as an encapsulation of first-generation and second-generation languages. a. True b. False

b

The unchecked exceptions in Java are objects of type IOException or any of its descendants. a. True b. False

b

When a method creates a Scanner object to read from a file (i.e., a Scanner object created with a File object as the parameter), the potential exception (e.g., FileNotFoundException or IOException) must be handled with try-catch blocks; there is no other alternative. a. True b. false

b

When a method is called, if an exception occurs and it is not caught and handled in the method, then the exception is printed immediately from the calling method rather being propagated to the calling method. a. True b. false

b

When a method uses a PrintWriter object to write to a file, simply invoking the println method on the PrintWriter object will ensure that the data is written to the file. a. True b. false

b

When a try block is executed (and System.exit is not called), the associated finally block (if it has one) will execute only if the try block does not throw an exception. a. True b. false

b

When the constructor of a subclass is called, the parameterless constructor in the super class is called only when the instance is created by a constructor with parameters. a. True b. False

b

With respect to inheritance, a subclass inherits instance variables and instance methods defined in its parent but not those defined in the ancestors of the parent. a. True b. False

b

Suppose s1 and s2 are objects of the String class, which implements the Comparable interface. If the values of s1 and s2 are "sun" and "son" respectively, what is the expected return value when s1.compareTo(s2) is called? [also: "sun".compareTo("son") ] a. false b. true c. An int value greater than zero d. An int value less than zero e. An int value equal to zero

c

Which of the following streams is typically associated with a program printing to the screen using the println method? a. System.err b. System.in c. System.out d. b & c above e. All of the above (a,b,&c)

c

What is the natural order of the array below? String[ ] pets = {"dog", "cat, "bird", "hamster"}; a. "cat,"dog","bird","hamster" b. "hamster", "dog", "cat, "bird" c. "dog","cat,"bird","hamster" d. "bird", "cat, "dog", "hamster" e. "bird","dog","cat,"hamster"

d

Which one of the following is a correct declaration and instantiation of an array? a. int[ ]scores; b. int[ ] scores = new int[1.5]; c. int[ ]scores={"low","high"}; d. int[ ] scores = new int[15]; e. All of the above

d

The signature of a method is determined by _____________________. a. name b. number of parameters c. type of parameters d. order of parameters e. All of the above

e

Which of the following are inherited by a subclass? (circle all that apply) a. public methods b. public variables c. protected variables d. protected methods e. all of the above (not constructors)

e


Related study sets

Characteristic of myoblast (Skeletal, smooth, and cardiac muscle functions)

View Set

Chapter 5: Law Enforcement Today

View Set