Font size
Worksheetsthrows keyword + java
Total questions: 89
Worksheet time: 30mins
What is the parameter type of the off parameter in the write method in the Writerclass?
What is the name of the method that is used to divide two numbers in the image?
Which of the following is the correct way to handle the exception in the image?
Use a try-catch block.
Use the throws keyword.
Both try-catch block and throws keyword can be used.
None of the above.
What is the name of the exception that is being thrown in the image?
What is the output of the program in the image?
Result of Division: 0
java.lang.ArithmeticException: divide by zero
Unreachable code
None of the above
What is the output of the program in the image?
welcome to vote
Exception in thread "main" java.lang.ArithmeticException: not valid
rest of the code.
None of the above
What is the purpose of the try-catch block in the image?
To check if the age is valid.
To print the message "welcome to vote" if the age is valid.
To handle the ExceptionClass exception.
None of the above.
What is the purpose of the throw keyword in the MyString class?
To create a new InvalidStringException object.
To throw an InvalidStringException exception.
To print the message "Invalid string" to the console.
To exit the program.
What is the purpose of the throws keyword in the method(int i) method?
To declare that the method(int i) method may throw an IllegalArgumentException exception.
To throw an IllegalArgumentException exception.
To print the message "Invalid argument" to the console.
To exit the program.
What is the purpose of the throw keyword in the divideInt() method?
To create a new IllegalArgumentException object.
To throw an IllegalArgumentException exception.
To print the message "Divinor cannot be zero!" to the console.
To exit the program.
What is the purpose of the throws keyword in the CustomThrower class?
To declare that the CustomThrower class may throw a MyThrowable exception.
To throw a MyThrowable exception.
To print the message "MyThrowable exception thrown" to the console.
To exit the program.
Which of the following is the correct output of the program in the image?
Line is striine
Unreachable code
java.io.FileNotFoundException: F:\abc.txt (The system cannot find the file specified)
java.lang.NullPointerException
Which of the following is the purpose of the throws keyword in the main() method?
To declare that the main() method may throw a FileNotFoundException exception.
To throw a FileNotFoundException exception.
To print the message "File not found" to the console.
To exit the program.
Question: Which of the following is the purpose of the throw keyword in the m() method?
To throw a NullPointerException exception.
To print the message "NullPointerException" to the console.
To exit the program.
None of the above.
What is the purpose of the throws keyword in the MyClass class?
To declare that the MyClass class may throw a NullPointerException exception.
To throw a NullPointerException exception.
To print the message "NullPointerException" to the console.
To exit the program.
What is the purpose of the throws keyword in the readFromFile() method?
To declare that the readFromFile() method may throw a FileNotFoundException exception.
To throw a FileNotFoundException exception.
To print the message "File not found" to the console.
To exit the program.
What is the output of the program in the image?
Exception in thread "main" java.lang.ArithmeticException: divide by zero
Unreachable code
None of the above.
Question: What is the purpose of the throw keyword in the MyString class?
To throw an InvalidStringException exception.
To print the message "Invalid string" to the console.
To exit the program.
To declare that the MyString class may throw an InvalidStringException exception.
Which of the following is the purpose of the throws keyword in the main() method?
To declare that the main() method may throw a NullPointerException exception.
To throw a NullPointerException exception.
To print the message "NullPointerException" to the console.
To exit the program.
What is the purpose of the throw keyword in the method() method?
To throw an ArithmeticException exception.
To print the message "Invalid argument" to the console.
To exit the program..
To declare that the method() method may throw an ArithmeticException exception.
What is the purpose of the throw keyword in the MyString class?
To throw an InvalidStringException exception.
To print the message "Invalid string" to the console.
To exit the program.
To declare that the MyString class may throw an InvalidStringException exception.
Which of the following is the purpose of the throws keyword in the main() method?
To declare that the main() method may throw a NullPointerException exception.
To throw a NullPointerException exception.
To print the message "NullPointerException" to the console.
To exit the program.
Which of the following is the correct output of the program in the image?
Line is striine
Unreachable code
:java.lang.NullPointerException
java.io.FileNotFoundException
Which of the following is the purpose of the throws keyword in the readFromFile() method?
To declare that the readFromFile() method may throw a FileNotFoundException exception.
To throw a FileNotFoundException exception.
To print the message "File not found" to the console.
To exit the program.
What is the purpose of the throws keyword in the MyString class?
To declare that the MyString class may throw a NullPointerException exception..
To throw a NullPointerException exception.
To print the message "Invalid string" to the console.
To exit the program..
What is the output of the program in the image?
Line is striine
Unreachable code
java.lang.NullPointerException
What is the purpose of the try-catch statement in the image?
To catch the NullPointerException exception.
To print the message "This is a dummy exception" to the console.
To print the message "Line is striine" to the console.
To exit the program.
What is the output of the program in the image?
Line is striine
This is a dummy exception
Unreachable code
What is the purpose of the throws keyword in the MyString class?
To declare that the MyString class may throw a NullPointerException exception.
To throw a NullPointerException exception.
To print the message "Invalid string" to the console.
To exit the program.
What is the output of the program in the image?
Line is striine
This is a dummy exception
Unreachable code
What is the purpose of the throw keyword in the deleteFile() method?
To throw a FileNotFoundException exception.
To print the message "File not found" to the console.
To exit the program.
To declare that the deleteFile() method may throw a FileNotFoundException exception.
What is the output of the program in the image?
Line is striine
This is a dummy exception
Unreachable code
What is the purpose of the throw keyword in the divideInt() method?
To throw a ArithmeticException exception.
To print the message "Divisor cannot be zero!" to the console.
To exit the program..
To declare that the divideInt() method may throw an ArithmeticException exception.
What is the output of the program in the image?
Line is striine
This is a dummy exception
Unreachable code
Which of the following is the purpose of the throws keyword in the displayFile() method?
To throw a FileNotFoundException exception.
To print the message "File not found" to the console.
To exit the program.
To declare that the displayFile() method may throw a FileNotFoundException exception.
What is the output of the program in the image?
Line is striine
This is a dummy exception
Unreachable code
Which of the following is the type of exception that is thrown in the image?
Which of the following is the correct code to fix the error in the image?
public class Main {
public static void main(String[] args) {
String s = "striine";
if (s != null) {
System.out.println("Line is " + s);
} else {
throw new NullPointerException();
}
}
}
public class Main {
public static void main(String[] args) {
String s = "striine";
if (s == null) {
System.out.println("Line is null");
} else {
System.out.println("Line is " + s);
}
}
}
public class Main {
public static void main(String[] args) {
String s;
try {
s = "striine";
System.out.println("Line is " + s);
} catch (NullPointerException e) {
System.out.println("Line is null");
}
}
}
public class Main {
public static void main(String[] args) {
String s = null;
System.out.println("Line is " + s);
}
}
What is the output of the program in the image?
Line is null
This is a dummy exception
Unreachable code
What is the purpose of the throw keyword in the image?
To throw a NullPointerException exception.
To print the message "This is a dummy exception" to the console.
To exit the program.
To declare that the s variable may be null.
Which of the following is the correct code to fix the error in the image?
public class Main {
public static void main(String[] args) {
String s = null;
if (s != null) {System.out.println("Lineis " + s);
} else {
throw new NullPointerException();
}
}
}
public class Main {
public static void main(String[] args) {
String s = null;
if (s == null) {System.out.println("Line is null");
} else {
System.out.println("Line is " + s);
}
}
}
public class Main {
public static void main(String[] args) {
String s;
try {s = "striine";
System.out.println("Line is " + s);
} catch (NullPointerException e) {
System.out.println("Line is null");
}
}
}
public class Main {
public static void main(String[] args) {
String s = "striine";
System.out.println("Line is " + s);
}
}
Which keyword is used to throw an exception?
Throw [Image shows an arrow pointing to the word "Throw".]
What is the name of the exception that is thrown in the image?
CustomException [Image shows an arrow pointing to the word "CustonException".]
DenominatorCan'tBeZeroException
Which keyword is used to declare that a method can throw an exception?
throw [Image shows an arrow pointing to the word "throws".]
Which exception is declared to be thrown by the main() method in the image?
FileNotFoundException [Image shows an arrow pointing to the line of code throws FileNotFoundException.]
What is the difference between the throw and throws keywords in Java?
The throw keyword is used to explicitly throw an exception, while the throws keyword is used to declare that a method can throw an exception. [Image shows an arrow pointing to the word "throw" in the first column, and an arrow pointing to the word "throws" in the second column.]
The throw keyword can only be used to throw checked exceptions, while the throws keyword can be used to throw both checked and unchecked exceptions.
The throw keyword can only be used within a method, while the throws keyword can be used in a method declaration or in a class declaration.
The throw keyword can be used to throw multiple exceptions, while the throws keyword can only be used to throw one exception.
Which keyword is used to throw an exception in Java?
throw [Image shows an arrow pointing to the word "throw" in the line of code throw new FileNotFoundException("File not found");.]
Which keyword is used to check if a string is empty in Java?
isEmpty() [Image shows an arrow pointing to the word "isEmpty()" in the line of code if (content.isEmpty()).]
isBlank()
What is the name of the exception that is thrown in the image?
ArithmeticException [Image shows an arrow pointing to the word "ArithmeticException" in the line of code throw new ArithmeticException("Person is not eligible to vote");.]
Who is responsible for handling the exception thrown by the throw keyword?
The JVM [Image shows an arrow pointing to the word "JVM" in the column "Responsibility of handling exception".]
The caller method
The throw keyword itself
The throws keyword
Which keyword is used to declare that a method can throw an exception??
throw [Image shows an arrow pointing to the word "throws" in the column "Keyword used to declare that a method can throw an exception".]
Which keyword is used to throw an exception in Java?
throws [Image shows an arrow pointing to the word "throw" in the code.]
Which keyword is used to declare that a method can throw an exception?
throw [Image shows an arrow pointing to the word "throws" in the image.]
Which exception is thrown by the disp() method in the Exceptl class?
FileNotFoundException [Image shows an arrow pointing to the line of code throw new FileNotFoundException("File not found"); in the disp() method of the Exceptl class.]
Which keyword is used to throw an exception in Java?
throw [Image shows an arrow pointing to the word "throw" in the line of code throw new CustomException("This is a custom exception");.]
Which exception is thrown in the image?
ArrayIndexOutOfBoundsException [Image shows an arrow pointing to the line of code num/arr[i], where i is 10 and the array arr only has 5 elements.]
Which keyword is used to declare that a method can throw an exception?
throw [Image shows an arrow pointing to the word "throws" in the line of code public void disp() throws FileNotFoundException {}.]
Which exception is thrown in the image?
Which keyword is used to throw an exception in Java?
Which keyword is used to declare that a method can throw an exception??
Which exception is thrown by the getUserName() method?
Which keyword is used to declare that a method can throw a CustomException?
To exit the program.
What is the name of the exception that is thrown in the image?
Which exception is thrown in the image?
Which exception is thrown by the disp() method?
What keyword is used to declare that a method can throw an exception?
Which exception is declared to be thrown by the disp() method?
Which keyword is used to throw an exception in Java?
Which exception is thrown by the disp() method?
Which keyword is used to declare that a method can throw an exception?
Which exception is thrown by the disp() method?
Which exception is thrown by the disp() method?
What is the name of the exception that is thrown in the image?
What is the keyword used to declare that a method can throw an exception?
Which exception is thrown by the disp(int i) method?
What is the keyword that is used to declare that a method can throw an exception?
Which exception is declared to be thrown by the disp() method?
What is the keyword used to throw an exception in Java?
What is the name of the custom exception that is thrown by the disp() method?
Which exception is thrown by the disp() method?
What is the keyword used to declare that a method can throw an exception?
Which keyword is used to declare that a method can throw an exception?
Which exception is thrown by the disp() method?
What is the name of the exception that is thrown by the disp() method?
What is the name of the exception that is thrown by the disp() method?
What is the keyword used to throw an exception in Java?
What is the keyword used to declare that a method can throw an exception?
What is the keyword used to declare that a method can throw an exception?
Which exception is declared to be thrown by the disp() method?
