Java Exception Handling and Strings

Java Exception Handling and Strings

University

15 Qs

quiz-placeholder

Similar activities

TALENT-NEXT-JAVA-QUIZ1

TALENT-NEXT-JAVA-QUIZ1

University

20 Qs

JAVA I/O

JAVA I/O

University

10 Qs

Java Quiz 4

Java Quiz 4

University

15 Qs

JAVA Basics Quiz

JAVA Basics Quiz

University

20 Qs

Java

Java

University

11 Qs

Quiz 2 PBO

Quiz 2 PBO

University

20 Qs

BCSC0006 - Quiz 1 - Arrays

BCSC0006 - Quiz 1 - Arrays

University

10 Qs

Quiz PBO SIA

Quiz PBO SIA

University

20 Qs

Java Exception Handling and Strings

Java Exception Handling and Strings

Assessment

Quiz

Computers

University

Easy

Created by

Sowmya Koneru

Used 2+ times

FREE Resource

15 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

What are the two main categories of exceptions in Java?

Runtime exceptions and compile-time exceptions

Synchronous exceptions and asynchronous exceptions

Logical exceptions and physical exceptions

Checked exceptions and unchecked exceptions

2.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

What is the purpose of a try-catch block in Java?

To define variables in a method.

To optimize performance of the program.

To handle exceptions and prevent program crashes.

To improve code readability.

3.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

How do you create a custom exception class in Java?

public class MyCustomException { public MyCustomException() { } }

public class MyCustomException extends Exception { public MyCustomException(String message) { super(message); } public MyCustomException(String message, Throwable cause) { super(message, cause); }}

public class MyCustomException implements Exception { }

public class MyCustomException extends RuntimeException { }

4.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Which method is used to find the length of a string in Java?

length()

getLength()

size()

stringLength()

5.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

What is the difference between checked and unchecked exceptions?

Both checked and unchecked exceptions must be handled in the code.

Unchecked exceptions must be declared in the method signature.

Checked exceptions must be handled or declared; unchecked exceptions do not.

Checked exceptions are always runtime errors.

6.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

How do you handle multiple exceptions in a single catch block?

Only catch the most specific exception type.

Ignore exceptions and let them propagate up the call stack.

Use separate catch blocks for each exception type.

Use a single catch block with multiple exception types separated by a pipe (|).

7.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

What method would you use to convert a string to lowercase in Java?

string.lowercase()

string.toLowerCase()

string.toLower()

string.convertToLower()

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?