100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CS2 Exam Prep with complete solutions 2022 $12.99   Add to cart

Exam (elaborations)

CS2 Exam Prep with complete solutions 2022

 2 views  0 purchase
  • Course
  • Institution

While the Exception class is part of , IOException is part of . True In order to have some code throw an exception, you would use which of the following reserved words? Correct Response A) throw B) Throwable C) throws D) try E) goto Throw 00:27 01:14 The Scanne...

[Show more]

Preview 2 out of 11  pages

  • August 1, 2022
  • 11
  • 2022/2023
  • Exam (elaborations)
  • Questions & answers
avatar-seller
CS2 Exam Prep
While the Exception class is part of java.lang, IOException is part of java.io. - Answer
True

In order to have some code throw an exception, you would use which of the following
reserved words?
Correct Response

A) throw

B) Throwable

C) throws

D) try

E) goto - Answer Throw

The Scanner class provides an abstraction for input operations by

A) performing conversion operations from String to the appropriate type as specified in
the Scanner message

B) using try and catch statements to catch any IOException instead of throwing the
Exception elsewhere

C) parsing input lines into individual tokens

D) inputting from the standard input stream if create is called using System.in
Correct Response

E) all of the above - Answer All of the Above

Use the code below to answer the following questions. Note that the catch statements in
the code are not implemented, but you will not need those details. Assume filename is a
String, x is an int, a is a double array and i is an int. Use the comments i1, i2, i3, e1, e2,
e3, e4, e5 to answer the questions (i for instruction, e for exception handler).

try
{
BufferedReader infile = new BufferedReader(new FileReader(filename)); // i1
int x = Integer.parseInt(infile.readLine( )); // i2
a[++i] = (double) (1 / x); // i3
}

, catch (FileNotFoundException ex) {...} // e1
catch (NumberFormatException ex) {...} // e2
catch (ArithmeticException ex) {...} // e3
catch (ArrayIndexOutOfBounds ex) {...} // e4
catch (IOException ex) {...} // e5


An exception raised by the instruction in i1 would be caught by the catch statement
labeled

A) e5

B) e1

C) e2
Correct Answer

D) either e1 or e5
Incorrect Response

E) either e1, e4, or e5 - Answer D) either e1 or e5

While the Exception class is part of java.lang, IOException is part of java.io. - Answer
True

"class Aggregate" is incorrect. Choose the correct line so that this program prints
Granite: weight=25.0 value=4 numKind=7

public class Inherit
{

abstract class Stone
{
protected float weight = 13;
protected int value = 4;
abstract public String toString( );
}

class Aggregate
{
protected int numKind;
}

class Granite extends Aggregate
{
Granite( )
{

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller EvaTee. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $12.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

84146 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$12.99
  • (0)
  Add to cart