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

Java Quiz Lesson 5

The document contains a series of multiple-choice questions and answers related to Java programming concepts, including HashMap, abstract classes, threads, character sequences, interfaces, exception handling, arrays, thread creation, access modifiers, and the super keyword. Each question is followed by the correct answer, highlighting key features and behaviors of Java programming elements. The content serves as a quiz or study guide for Java developers.

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)
7 views4 pages

Java Quiz Lesson 5

The document contains a series of multiple-choice questions and answers related to Java programming concepts, including HashMap, abstract classes, threads, character sequences, interfaces, exception handling, arrays, thread creation, access modifiers, and the super keyword. Each question is followed by the correct answer, highlighting key features and behaviors of Java programming elements. The content serves as a quiz or study guide for Java developers.

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 is true about the HashMap class in Java?

A) HashMap maintains the order of elements based on their insertion order.

B) HashMap allows one null key and multiple null values.

C) HashMap allows duplicate keys but not values.

D) HashMap is thread-safe and can be used in multi-threaded environments.

Answer: B) HashMap allows one null key and multiple null values.

2. Which of the following statements is true about abstract classes in Java?

A) An abstract class can have both abstract and non-abstract methods.

B) An abstract class cannot have any non-abstract methods.

C) An abstract class can be instantiated.

D) All methods in an abstract class must be abstract.

Answer: A) An abstract class can have both abstract and non-abstract


methods.

3. Which of the following methods is used to stop a thread in Java?

A) Thread.stop()

B) Thread.suspend()

C) Thread.interrupt()

D) Thread.finish()

Answer: C) Thread.interrupt()

4. Which of the following classes is used to represent a sequence of


characters in Java?
A) String

B) StringBuffer

C) StringBuilder

D) All of the above

Answer: D) All of the above

5. Which of the following statements is true regarding Java interfaces?

A) An interface can contain only abstract methods.

B) An interface can contain both abstract and concrete methods.

C) An interface can contain instance variables.

D) An interface can be instantiated like a class.

Answer: B) An interface can contain both abstract and concrete methods.

6. Which of the following statements is true about the finally block in


exception handling?

A) The finally block is executed only if an exception is caught.

B) The finally block is executed only if no exception is caught.

C) The finally block is always executed, regardless of whether an exception is


caught or not.

D) The finally block can only be used with checked exceptions.

Answer: C) The finally block is always executed, regardless of whether an


exception is caught or not.

7. What is the result of the following code?


int[] arr = new int[5];

System.out.println(arr[0]);

A) 0

B) null

C) ArrayIndexOutOfBoundsException

D) Compilation error

Answer: A) 0

Explanation: In Java, arrays of primitive types like int are initialized with
default values. For int, the default value is 0.

8. Which of the following is the correct way to create a thread in Java?

A) Thread t = new Thread();

B) Thread t = new Runnable();

C) Thread t = new Thread(Runnable);

D) Thread t = new Thread(new Runnable());

Answer: D) Thread t = new Thread(new Runnable());

9. Which of the following statements is true about the public access modifier
in Java?

A) It allows access only within the same package.

B) It allows access to the class or member from any other class in any
package.

C) It restricts access to the current class only.

D) It allows access within the same package and its subclasses.


Answer: B) It allows access to the class or member from any other class in
any package.

10. Which of the following statements is true about the super keyword in
Java?

A) It is used to call a method from the current class.

B) It is used to refer to the immediate parent class of the current object.

C) It is used to create an instance of the current class.

D) It is used to call the constructor of the current class.

Answer: B) It is used to refer to the immediate parent class of the current


object.

You might also like