[go: up one dir, main page]

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

Quiz 2

Uploaded by

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

Quiz 2

Uploaded by

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

Beginner Level

1. What is the correct syntax for the main method in Java?

o A) public static int main(String args[])

o B) public static void main(String args[])

o C) public int main(String args[])

o D) public void main(String args[])

2. What will System.out.println(2 + 3 + "Hello"); output?

o A) Hello5

o B) 5Hello

o C) Hello23

o D) Error

3. Which of these is a valid keyword in Java?

o A) interface

o B) string

o C) Float

o D) unsigned

4. Which package contains the Scanner class?

o A) java.io

o B) java.util

o C) java.lang

o D) java.text

5. What is the size of an int variable in Java?

o A) 8 bytes

o B) 2 bytes

o C) 4 bytes

o D) 1 byte

6. Which of the following is a wrapper class in Java?

o A) Integer

o B) int

o C) String

o D) float
7. What is the default value of a boolean variable in Java?

o A) true

o B) false

o C) null

o D) 0

8. Which operator is used to compare two values in Java?

o A) =

o B) ==

o C) !=

o D) :=

9. Which of the following is used for looping in Java?

o A) if

o B) switch

o C) for

o D) try

10. Which of these is the correct way to create an array in Java?

o A) int arr[] = new int(5);

o B) int arr[] = new int[5];

o C) int arr[5] = new int[];

o D) int arr(5) = new int[];

Intermediate Level

11. Which of these keywords is used to handle exceptions in Java?

o A) try

o B) catch

o C) finally

o D) All of the above

12. What is the output of System.out.println("Hello" + " World!");?

o A) HelloWorld!

o B) Hello World!

o C) Hello + World!
o D) Hello + "World!"

13. Which of the following is true about a final class in Java?

o A) It cannot be extended.

o B) It can be extended.

o C) It can be instantiated.

o D) It has no methods.

14. What is a constructor in Java?

o A) A method to initialize objects

o B) A method that returns an int

o C) A method that returns void

o D) A method that calculates values

15. Which Java keyword is used to inherit a class?

o A) extends

o B) implements

o C) inherits

o D) super

16. What does the break keyword do inside a loop?

o A) Continues to the next iteration

o B) Exits the loop

o C) Skips the current iteration

o D) Exits the method

17. In Java, which statement is used to end the execution of a method and return a value to
the caller?

o A) break

o B) exit

o C) return

o D) continue

Advanced Level

18. Which of these statements about Java Threads is true?

o A) Threads can be created by implementing the Runnable interface.


o B) Java does not support multithreading.

o C) Threads in Java can only be created by extending the Thread class.

o D) A thread can only have a single state at any time.

19. What is a lambda expression in Java?

o A) A way to define anonymous functions

o B) A new type of loop

o C) A way to define constants

o D) A way to create threads

20. Which Java feature allows fields and methods to be accessed in subclasses even if they are
in different packages?

o A) public

o B) protected

o C) private

o D) default

You might also like