COSC 1337 Test 2 Review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which of the following is not a java.io package output class: All of these are java.io output classes FileWriter OutputStream PrintWriter Writer

All of these are java.io output classes

Which of the following is not a method of exception classes: All of these are valid answers toString() getMessage() printStackTrace()

All of these are valid answers

When a class implements an interface, we inherit any default, public, and static methods but we must provide method bodies for all the abstract methods.

true

When we open a file for appending, we will be adding data to the end of the file.

true

How do you instantiate an object from an abstract class?

you cannot

You need to read objects from a text file. What input class would be the most appropriate? FileInputStream InputStream Scanner ObjectInputStream

ObjectInputStream

Which of the following output classses is an abstract superclass?

OutputStream

Given the code snippet below, what is the output of this code sequence: // b2 is a B object reference System.out.println(b2.foo3());

A version of foo3() is called Hi

Which of the following can be interface members: a. All of these b. Constants c. Methods d. Other interfaces e. Classes

All of these

Which of the following must be true in order to use polymorphism: a. The classes must all be in the same hierarchy b. All the subclasses override the same method c. A subclass object reference is assigned to a superclass object reference d. All of these e. The superclass object reference is used to call the overridden method

All of these

Given the code snippet below, what is the output of this code sequence: // b1 is a B object reference and number has been set to 10 System.out.println(b1.foo1);

B version of foo1() is called

An abstract class always serves as a subclass

False

Writer is a subclass of OutputStream.

False

Which of the following is not a Java.io input class: File FileInputStream InputStream Scanner ObjectInputStream

File? Scanner

Which of the following input classes is used to read raw bytes of data from a file? FileInputStream None of these Scanner ObjectInputStream

FileInputStream

Which of the following output classes is a convenience class specifically for writing characters to a file?

FileWriter

If the interface only has one abstract method to implement, what is the interface called?

Functional

Which of the following is an abstract superclass? ObjectInputStream FileInputStream InputStream Scanner

InputStream

In this code snippet, would a class extending Base be able to override the method fun? Why? abstract class Base {final void fun() { System.out.println("Derived fun() called"); }}

No, because fun() is a final method

Which of the following is true of polymorphism: a. Polymorphism allows the same method call to be used for any object in the hierarchy b. The fact that an object of a subclass is also an object of any of its superclasses is a basis for polymorphism c.Polymorphism allows us to perform a single action (method) in different ways d. all of the above

all of the above

To inherit from an interface, a class declares that it _________the interface.

implements

What Java keyword is used ina class header when a class is defined as inheriting from an interface?

implements

in what package can the RuntimeException class be found?

java.lang

Which of the following Scanner and File class methods can throw an exception? (You may need to select more than one answer) nextFloat() hasNextInt() Constructor for Scanner close()

nextFloat() hasNextInt() Constructor for Scanner

When we associate a file with an input stream or output stream, we are ...

opening the file

The _____ exception class method will print the line number of the code that caused the exception.

printStackTrace()

You have been assigned to create a public interface called Library. Which of the following uses the correct syntax for defining it?

public interface Library { // body of interface }

If a class contains an abstract method, then

the class must be declared as abstract

If a class contains an abstract method, then ...

the class must be declared as abstract

When we open a file for writing,

the contents of the file are deleted, if any,

abstract class Base { void fun() { System.out.println("Base fun() called"); } } class Derived extends Base { } class Main {public static void main(String args[]) {Derived d = new Derived(); d.fun(); }}

this code will run without any problem

A Java class can implement one or more interfaces.

true

A class can implement 0, 1, or more interfaces

true

A variable defined within a try block is not local to just that block.

true

All interfaces are abstract

true

An abstract method is a method that is declared without an implementation

true

Calling the close method on a file is optional.

true

If a subclass does not provide implementations for all of the abstract methods in its parent class, then it must also be declared as abstract

true

If the code in the try block could generate multiple exception types, we can provide multiple catch blocks to handle the exceptions.

true

In Java, the abstract modifier must be applied to each abstract method.

true

In Java, we use the modifier abstract on the class header to declare a class as abstract.

true

System.in and System.err should not be closed.

true

The Exception class is the superclass of all exception classes.

true

The java.io package contains classes for input and output operations.

true

The scanner class can be used to read from a text file.

true

Given the code snippet below, what is the error? public class K {public void mys();}

Class K and method mys must be declared abstract

You are writing a program that will read in integer data from a text file. Which of the following exceptions should be accounted for if you use try-with-resources? (You may need to select more than one answer)

NoSuchElement Exception FileNotFound Exception

The extends keyword applies to ...

a class inheriting from another class

Which of the following best describes an abstract class in Java:

a class that is declared abstract

Which of the following statements is most accurate:

The first catch block with a parameter that matches the exception thrown will execute, then any remaining catch blocks will be skipped

Using the code snippet below, identify the error in this code sequence: C c2;c2 = new D(); There is no constructor for C or D There is no error Because C is an abstract class, it cannot be instantiated

There is no error

Which of the following is NOT TRUE about abstract classes in Java:

They can be instantiated

Multiple classes can inherit from an abstract class

True

RuntimeException is a superclass of InputMismatchException.

True

Unchecked exceptions are always subclasses of Error or RuntimeException.

true

Which of the following is not a valid type of method in an interface: All of these are valid public abstract public default private

alll of these are valid

If we open a file for reading and the file does not exist ...

an exception is thrown

In Java, multiple inheritance is implemented using the concept of

an interface

Illegal operations generate ______.

exceptions

An abstract class cannot be declared but it can be instantiated

false

At compile-time, the JVM will determine to which class in the hierarchy the object belongs and calls the appropriate version of the method for that class.

false

Code that could generate a checked exception does not have to be coded within a try block.

false

IOException is an example of an unchecked exception.

false

In Java, if a class contains abstract methods it does not have to be declared abstract

false

In polymorphism, not all the subclasses have to override the same method

false

Interfaces can be instantiated

false

NumberFormatException must be coded within a try block because it is an unchecked exception.

false

The IndexOutOfBounds exception class is a subclass of IOException.

false

The curly braces around the various try, catch, and finally blocks are required only if the block contains more than one statement.

false

This method is abstract: public void myMethod( ) { }

false

Try/catch blocks are useful because they can replace selection statements, which results in CPU time savings.

false

When coding a try and catch block, it is mandatory to code a finally block.

false

in Java, an abstract class is a template definition of methods and variables of a class that include one or more abstract methods

false

Scanner is in the java.io package.

false, it is in java.util

A ________ block contains code to execute regardless of whether an exception occurs.

finally

Which method only returns a message indicating the cause of the exception:

getMessage()

_________ refers to an attempt to recover from an exception and continue running the program.

handling the exception


संबंधित स्टडी सेट्स

Live Virtual Machine Lab 3.2: Module 03 Install and Configure DHCP and DNS Servers

View Set

Adding and Subtracting Fractions with Like Denominators

View Set

Series 79 Knopman Marks Limited Representative Investment Banking Exam 8th Edition

View Set

Era 3 world history--short version long answers

View Set