Computer science JAVA multiple choice questions Question 6 What is wrong in the
ID: 667739 • Letter: C
Question
Computer science JAVA multiple choice questions
Question 6
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 or a finally block
A method call that does not declare exceptions cannot be placed inside a try block
You cannot have a try block without a catch block
Question 7
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 compile without any errors
The program will not compile because Exception is an unchecked exception
The program will not compile because a throws clause is needed
Save
Question 8
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
Either one can be used to throw an exception
throw is a reserved word, but throws is not
The two reserved words are interchangeable
Question 9
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:
Both exceptions will be caught
Only the RuntimeException will be caught
The program will no longer compile
The change will have no effect, the program will work the same as before
Question 10
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 exception is rethrown
The program always terminates and displays an error message
The exception is ignored
Explanation / Answer
6)
correct answer is You cannot have a try block without a catch block or a finally block
7)
The program will not compile because Exception is an unchecked exception
8)
throws is used in a method signature, throw is used to throw an exception
9)
Both the exceptions will be caught
output will be
10)
The exception is propagated to the method that called the current method
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.