Question 1 (5 points) Question 1 Unsaved What is displayed on the console when r
ID: 3664530 • Letter: Q
Question
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 {}
Explanation / Answer
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 {}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.