0% found this document useful (0 votes)
8 views4 pages

Java Quiz Lesson 4

The document contains a series of multiple-choice questions and answers related to Java programming concepts. Key topics include thread creation, object references, garbage collection, exception handling, string manipulation, and collection types. The correct answers are provided for each question, highlighting important Java features and behaviors.

Uploaded by

rose oriana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Java Quiz Lesson 4

The document contains a series of multiple-choice questions and answers related to Java programming concepts. Key topics include thread creation, object references, garbage collection, exception handling, string manipulation, and collection types. The correct answers are provided for each question, highlighting important Java features and behaviors.

Uploaded by

rose oriana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Which of the following keywords is used to create a thread in Java?

A) new

B) Thread

C) Runnable

D) extend

Answer: B) Thread

2. What is the default value of an object reference in Java?

A) 0

B) null

C) false

D) "" (empty string)

Answer: B) null

3. Which of the following is used to force garbage collection in Java?

A) System.gc()

B) gc.collect()

C) Runtime.collect()

D) System.cleanup()

Answer: A) System.gc()

4. Which of the following interfaces is used by Java to support the collection


of objects?

A) List
B) Set

C) Collection

D) Queue

Answer: C) Collection

5. Which of the following is the correct way to handle checked exceptions in


Java?

A) Use a try-catch block or declare the exception using the throws keyword.

B) Always use a try-catch block to handle checked exceptions.

C) Throw the exception explicitly and do not handle it.

D) You cannot handle checked exceptions in Java.

Answer: A) Use a try-catch block or declare the exception using the throws
keyword.

6. Which of the following methods can be used to check the length of a string
in Java?

A) length()

B) size()

C) count()

D) getSize()

Answer: A) length()

7. Which of the following is true about the StringBuilder class in Java?

A) It is immutable, meaning its contents cannot be modified once created.


B) It is mutable and used to create strings that can be modified without
creating new objects.

C) It can only be used for string concatenation in multithreaded applications.

D) It is not thread-safe and should not be used in single-threaded


applications.

Answer: B) It is mutable and used to create strings that can be modified


without creating new objects.

8. Which of the following collections does not allow null elements in Java?

A) HashSet

B) TreeSet

C) ArrayList

D) LinkedList

Answer: B) TreeSet

9. What is the purpose of the transient keyword in Java?

A) It makes a variable accessible across different threads.

B) It indicates that a variable should not be serialized.

C) It indicates that a variable should be included in the final output.

D) It makes a variable constant during execution.

Answer: B) It indicates that a variable should not be serialized.

10. Which of the following is the superclass of all exceptions in Java?

A) Throwable

B) Error
C) Exception

D) RuntimeException

Answer: A) Throwable

You might also like