Question

Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the...

Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the following program? public class Quiz2B { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } } } Question 1 options: The program displays Welcome to Java two times. The program displays Welcome to Java three times. The program displays Welcome to Java two times followed by End of the block. The program displays Welcome to Java three times followed by End of the block. Save Question 2 (5 points) Question 2 Unsaved Under what conditions must a throws clause be added to a method signature Question 2 options: Whenever any unchecked exception that can be thrown by the method is not caught Whenever any checked exception can be thrown by the method Whenever any exception can be thrown by the method Whenever any checked exception that can be thrown by the method is not caught Save Question 3 (5 points) Question 3 Unsaved What is displayed on the console when running the following program? public class Quiz2C { public static void main(String[] args) { try { method(); System.out.println("After the method call"); } catch (NumberFormatException ex) { System.out.println("NumberFormatException"); } catch (RuntimeException ex) { System.out.println("RuntimeException"); } } private static void method() { String s = "8.3"; Integer.parseInt(s); int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } } Question 3 options: The program has a compilation error The program displays NumberFormatException followed by RuntimeException The program displays NumberFormatException followed by After the method call The program displays NumberFormatException Save Question 4 (5 points) Question 4 Unsaved What exceptions will be caught by a catch block that catches exceptions of the class RuntimeException? Question 4 options: Only exceptions of type RuntimeException Exceptions of type RuntimeException and any of its subclasses Any exception Exceptions of type RuntimeException and any of its superclasses Save Question 5 (5 points) Question 5 Unsaved What exception type does the following program throw? public class Quiz2D { public static void main(String[] args) { Object object = new Object(); String string = (String) object; } } Question 5 options: StringIndexOutOfBoundsException ClassCastException ArithmeticException No exception Save Question 6 (5 points) Question 6 Unsaved What is wrong in the following program? public class Quiz2E public static void main(String[] args) { try { System.out.println("Hello world"); } } } Question 6 options: Nothing is wrong You cannot have a try block without a catch block You cannot have a try block without a catch block or a finally block A method call that does not declare exceptions cannot be placed inside a try block Save Question 7 (5 points) Question 7 Unsaved Select the correct statement regarding the program show below: public class Quiz2G { public static void main(String[] args) { if (Integer.parseInt(args[0]) == 0) throw new Exception("Invalid Command Line Argument"); } } Question 7 options: The program will not compile because parseInt could throw NumberFormatException and it is never caught The program will not compile because a throws clause is needed The program will not compile because Exception is an unchecked exception The program will compile without any errors Save Question 8 (5 points) Question 8 Unsaved The difference between throw and throws is correctly explained by which of the following statements? Question 8 options: The two reserved words are interchangeable throws is used in a method signature, throw is used to throw an exception throw is a reserved word, but throws is not Either one can be used to throw an exception Save Question 9 (5 points) Question 9 Unsaved What will occur if the catch block in program show below are reversed? class Quiz2H { public static void main(String[] args) { try { aMethod(); System.out.println("After the call"); } catch (ArithmeticException exception) { System.out.println("Arithmetic Exception"); } catch (RuntimeException exception) { System.out.println("Runtime Exception"); } System.out.println("After the try-catch statement"); } private static void aMethod() throws RuntimeException { int x = 1/0; } } Question 9 options: The change will have no effect, the program will work the same as before The program will no longer compile Only the RuntimeException will be caught Both exceptions will be caught Save Question 10 (5 points) Question 10 Unsaved What occurs when an exception is not caught in the current method? Question 10 options: The exception is propagated to the method that called the current method The program always terminates and displays an error message The exception is rethrown The exception is ignored Save Question 11 (5 points) Question 11 Unsaved Which of the following statements about type compatibility is true? Question 11 options: An object of a subclass can be assigned to a reference to its superclass, but type casting is required Assigning an object of a superclass to a reference to one of its subclasses always causes a compilation error whether type casting is used or not An object of a superclass can be assigned to a reference to one of its subclasses without casting An object of a subclass can be assigned to a reference to its superclass without a type cast Save Question 12 (5 points) Question 12 Unsaved Which of the following statements about final classes is correct? Question 12 options: A final class must have all abstract methods A final class cannot have any instances A final class cannot be extended A final class cannot have a constructor Save Question 13 (5 points) Question 13 Unsaved Which of the following expressions evaluates to false? class C1 {} class C2 extends C1 { } class C3 extends C2 { } class C4 extends C1 {}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 1 (5 points)
Question 1 Unsaved
What is displayed on the console when running the following program?
public class Quiz2B
{
public static void main(String[] args)
{
try
{
System.out.println("Welcome to Java");
int i = 0;
int y = 2 / i;
System.out.println("Welcome to Java");
}
catch (RuntimeException ex)
{
System.out.println("Welcome to Java");
}
finally
{
System.out.println("End of the block");
}
}
}
Question 1 options:
The program displays Welcome to Java two times followed by End of the block.

Question 2 (5 points)
Question 2 Unsaved
Under what conditions must a throws clause be added to a method signature
Question 2 options:
Whenever any checked exception that can be thrown by the method is not caught

Save Question 3 (5 points)
Question 3 Unsaved
What is displayed on the console when running the following program?
public class Quiz2C
{
public static void main(String[] args)
{
try
{
method();
System.out.println("After the method call");
}
catch (NumberFormatException ex)
{
System.out.println("NumberFormatException");
}
catch (RuntimeException ex)
{
System.out.println("RuntimeException");
}
}
private static void method()
{
String s = "8.3";
Integer.parseInt(s);
int i = 0;
int y = 2 / i;
System.out.println("Welcome to Java");
}
}
Question 3 options:
The program displays NumberFormatException

Save Question 4 (5 points)
Question 4 Unsaved
What exceptions will be caught by a catch block that catches exceptions of the class RuntimeException?
Question 4 options:
of type RuntimeException and any of its subclasses

Save Question 5 (5 points)
Question 5 Unsaved
What exception type does the following program throw?
public class Quiz2D
{
public static void main(String[] args)
{
Object object = new Object();
String string = (String) object;
}
}
ClassCastException


Save Question 6 (5 points)
Question 6 Unsaved

What is wrong in the following program?
public class Quiz2E
{
public static void main(String[] args)
{
try
{
System.out.println("Hello world");
}
}
}
Question 6 options:
You cannot have a try block without a catch block or a finally block

Save Question 7 (5 points)
Question 7 Unsaved
Select the correct statement regarding the program show below:
public class Quiz2G
{
public static void main(String[] args)
{
if (Integer.parseInt(args[0]) == 0)
throw new Exception("Invalid Command Line Argument");
}
}
Question 7 options:
The program will not compile because Exception is an unchecked exception

Save Question 8 (5 points)
Question 8 Unsaved
The difference between throw and throws is correctly explained by which of the following statements?
Question 8 options:
throws is used in a method signature, throw is used to throw an exception

Save Question 9 (5 points)
Question 9 Unsaved
What will occur if the catch block in program show below are reversed?
class Quiz2H
{
public static void main(String[] args)
{
try
{
aMethod();
System.out.println("After the call");
}
catch (ArithmeticException exception)
{
System.out.println("Arithmetic Exception");
}
catch (RuntimeException exception)
{
System.out.println("Runtime Exception");
}
System.out.println("After the try-catch statement");
}
private static void aMethod() throws RuntimeException
{
int x = 1/0;
}
}
Question 9 options:
The program will no longer compile

Save Question 10 (5 points)
Question 10 Unsaved
What occurs when an exception is not caught in the current method?
Question 10 options:
The exception is propagated to the method that called the current method

Save Question 11 (5 points)
Question 11 Unsaved
Which of the following statements about type compatibility is true?
Question 11 options:
An object of a subclass can be assigned to a reference to its superclass without a type cast

Save Question 12 (5 points)
Question 12 Unsaved
Which of the following statements about final classes is correct?
Question 12 options:
A final class cannot be extended

Save Question 13 (5 points)
Question 13 Unsaved
Which of the following expressions evaluates to false?
class C1 {}
class C2 extends C1 { }
class C3 extends C2 { }
class C4 extends C1 {}

Add a comment
Know the answer?
Add Answer to:
Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 5 (10 points) Assume you have the following code, with blanks to be filled in...

    Question 5 (10 points) Assume you have the following code, with blanks to be filled in below. public static void g () ( throw new () public static void f() try ) catch ( 12), e) System.out.print ("A") ; return } catch ( System.out. print ("B") throw ei e) ( 13) catch ( 14) e) ( System.out.print ("C") ; } finally System.out.print ("D") ; System.out.print ("E") ; } public static void main (String (] args) try f() } catch (...

  • What is wrong with this code? Please bold the changes that were made so this code...

    What is wrong with this code? Please bold the changes that were made so this code runs properly. The Problem is: 11.16 (Catching Exceptions with SuperClasses) Use inheritance to create an exception superclass (called Exception) and exception subclasses ExceptionB and ExceptionC, where ExceptionB inherites from ExceptionA and ExceptionC inherits from ExeptionB. Write a program to demonstrate that the catch block for type ExceptionA catches exceptions of types ExceptionB and ExceptionC. I got this far but I'm still getting a lot...

  • Java Method Resolution : Consider the following example: What is printed on the console if Main...

    Java Method Resolution : Consider the following example: What is printed on the console if Main is executed, and why? How the codes could be improved? public class Main {     public static void main(String[] args) throws Exception {         A obj = null;         obj.foo();     } } public class A {     public void foo() {         System.out.println(“foo in A”);     } }

  • Question 1 8 pts Write all the different possible outputs of the following Java multi-threaded program:...

    Question 1 8 pts Write all the different possible outputs of the following Java multi-threaded program: class MultithreadingDemo extends Thread public void runot try{ System.out.println (--Multithread.countDown): catch (Exception e) w public class Multithread{ public static int countDown = 10; public static void main(String[] args) { for (int i = 0; i < 3; i++) { MultithreadingDemo object = new MultithreadingDemol); object.start(); } میه

  • What is the output of the following question? import java.io.IOException; import java.util. EmptyStackException: public class newclass...

    What is the output of the following question? import java.io.IOException; import java.util. EmptyStackException: public class newclass public static void main(String[] args) try System.out.printf("%d", 1); throw (new Exception()); catch (IOException e) System.out.printf("%d", 2); catch(EmptyStackException e) System.out.printf("%d", 3); catch(Exception e) System.out.printf("%d", 4); } finally System.out.printf("%d", 5); Q3) (15 points) a.Write a JAVA program that reads an arra JAVA program that reads an array from input file and invo Sort and Max ,that sorts the elements of the array and s the elements...

  • Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly...

    Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly below): //Create public class count public class Count {     public static void main(String args[])     {         int n = getInt("Please enter an integer value greater than or equal to 0");                System.out.println("Should count down to 1");         countDown(n);                System.out.println();         System.out.println("Should count up from 1");         countUp(n);     }            private static void countUp(int n)     {...

  • /************************************************************************************ * Program: PRG/420 Week 5 * Purpose: Week 5 Coding Assignment * Programmer: TYPE YOUR...

    /************************************************************************************ * Program: PRG/420 Week 5 * Purpose: Week 5 Coding Assignment * Programmer: TYPE YOUR NAME HERE * Class: PRG/420 * Creation Date: TYPE TODAY'S DATE HERE ************************************************************************************* * Program Summary: * This program converts a given date to a string. * The code includes exception handling for a ParseException. ************************************************************************************/ package prg420week5_codingassignment; import java.util.*; // wildcard to import all the util. classes import java.text.*; // wildcard to import all the text classes public class PRG420Week5_CodingAssignment { public static...

  • the question, this is not running it throws an exception would you help me it is...

    the question, this is not running it throws an exception would you help me it is a java program // why this is not running would you help me public class sample {     public static void main(String[] args){         String str[][] = new String[10]['K'];                 for(int i= 1;i<=10; i++){             for(char j= 'A';j<='J'; j++){                 System.out.print(i +" "+ j);                  str[i][j] = "A";                   System.out.print(" ");                                                   }              System.out.println();                                  }            ...

  • import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {              ...

    import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {               int total = 0;               int num = 0;               File myFile = null;               Scanner inputFile = null;               myFile = new File("inFile.txt");               inputFile = new Scanner(myFile);               while (inputFile.hasNext()) {                      num = inputFile.nextInt();                      total += num;               }               System.out.println("The total value is " + total);        } } /* In the first program, the Scanner may throw an...

  • Problem 1 1. In the src → edu.neiu.p2 directory, create a package named problem1. 2. Create...

    Problem 1 1. In the src → edu.neiu.p2 directory, create a package named problem1. 2. Create a Java class named StringParser with the following: • A public static method named findInteger that takes a String and two char variables as parameters (in that order) and does not return anything. • The method should find and print the integer value that is located in between the two characters. You can assume that the second char parameter will always follow the first...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT