Blog - Java Quiz 2

Java Quiz 2

Java Quiz 2

Java

1.What is the output of the code snippet: int x = 10; System.out.println(x++);? 

कोड स्निपेट का आउटपुट क्या है:

a) 11 

b) 10

c) 12

d) 9

Answer: b) 10

 

2.Which Java keyword is used to exit from a loop prematurely?

लूप से समय से पहले बाहर निकलने के लिए किस जावा कीवर्ड का उपयोग किया जाता है?

a) break

b) exit

c) continue

d) return

Answer: a) break

 

3.Which collection interface in Java does not allow duplicate elements?

जावा में कौन सा संग्रह इंटरफ़ेस डुप्लिकेट तत्वों की अनुमति नहीं देता है?

a) List

b) Set

c) Map

d) Queue

Answer: b) Set

 

4.What is the purpose of the "StringBuilder" class in Java?

जावा में "स्ट्रिंगबिल्डर" वर्ग का उद्देश्य क्या है?

a) To create static methods.

b) To format strings.

c) To build and manipulate strings efficiently.

d) To read from a file.

Answer: c) To build and manipulate strings efficiently.

 

5. How is an abstract class different from an interface in Java?

एक अमूर्त वर्ग जावा में एक इंटरफ़ेस से किस प्रकार भिन्न है?

a) An abstract class can have both abstract and concrete methods; an interface can only have abstract methods.

b) An abstract class cannot have any methods; an interface can have both abstract and concrete methods.

c) An abstract class cannot have fields; an interface can have fields.

d) An abstract class cannot be extended; an interface can be implemented.

Answer: a) An abstract class can have both abstract and concrete methods; an interface can only have abstract methods.

 

6.Which Java keyword is used to prevent a method from being overridden?

किसी विधि को ओवरराइड होने से रोकने के लिए किस जावा कीवर्ड का उपयोग किया जाता है?

a) final

b) static

c) private

d) abstract Answer: a) final

 

7.What is the purpose of the "default" switch case in a switch statement?

स्विच स्टेटमेंट में "डिफ़ॉल्ट" स्विच केस का उद्देश्य क्या है?

a) To specify the default value for a variable.

b) To handle exceptions.

c) To execute code when no other case matches.

d) To set the default constructor.

Answer: c) To execute code when no other case matches.

 

8.What is the output of the code snippet:

System.out.println(Math.max(5, 10));?

कोड स्निपेट का आउटपुट क्या है:

a) 5

b) 10

c) 15

d) 0

Answer: b) 10

 

9.Which of the following is not a valid access modifier in Java?

निम्नलिखित में से कौन सा जावा में वैध एक्सेस संशोधक नहीं है?

a) public

b) private

c) protected

d) global

Answer: d) global

 

10. What is the purpose of the "implements" keyword in Java?

जावा में "इम्प्लीमेंट्स" कीवर्ड का उद्देश्य क्या है?

a) To define a new class.

b) To extend a superclass.

c) To implement an interface.

d) To create an object.

Answer: c) To implement an interface.

 

11. Which Java class is used to create and manage threads?

थ्रेड बनाने और प्रबंधित करने के लिए किस जावा क्लास का उपयोग किया जाता है?

a) Thread

b) Process

c) Runnable

d) Executor

Answer: a) Thread

 

12. What is the output of the code snippet: System.out.println("Hello".charAt(2));?

कोड स्निपेट का आउटपुट क्या है:

a) H

b) e

c) l

d) l

Answer: c) l

 

13. Which of the following is not a valid declaration of a variable in Java?

निम्नलिखित में से कौन सा जावा में एक वेरिएबल की वैध घोषणा नहीं है?

a) int myVar = 10;

b) float _value = 3.14;

c) double 3point = 3.0;

d) String $name = "John";

Answer: c) double 3point = 3.0;

 

14. How do you declare a constant in Java that is accessible across classes and packages?

आप जावा में एक स्थिरांक की घोषणा कैसे करते हैं जो कक्षाओं और पैकेजों में पहुंच योग्य है?

a) Using the "constant" keyword.

b) Constants cannot be declared across classes and packages.

c) Using the "final" keyword.

d) Using the "public" keyword.

Answer: d) Using the "public" keyword.

 

15. Which Java class is used to read input from the keyboard?

कीबोर्ड से इनपुट पढ़ने के लिए किस जावा क्लास का उपयोग किया जाता है?

a) Scanner

b) BufferedReader

c) InputReader

d) KeyboardReader

Answer: a) Scanner

 

16. What is the purpose of the "instanceof" operator in Java?

जावा में "इंस्टेंसऑफ़" ऑपरेटर का उद्देश्य क्या है?

a) To check if an object is an instance of a specific class or interface.

b) To compare two instances of the same class.

c) To determine if a variable is declared.

d) To perform type casting.

Answer: a) To check if an object is an instance of a specific class or interface.

 

17. What is the default value of a local variable in Java?

जावा में स्थानीय चर का डिफ़ॉल्ट मान क्या है?

a) 0

b) 1

c) null

d) It must be assigned a value before use.

Answer: d) It must be assigned a value before use.

 

18. Which Java operator is used to perform logical AND?

तार्किक AND निष्पादित करने के लिए किस जावा ऑपरेटर का उपयोग किया जाता है?

a) &

b) &&

c) |

d) ||

Answer: b) &&

 

19. Which of the following is not a valid primitive data type in Java?

निम्नलिखित में से कौन सा जावा में वैध आदिम डेटा प्रकार नहीं है?

a) byte

b) short

c) decimal

d) long

Answer: c) decimal

 

20. What is the purpose of the "throw" keyword in Java?

जावा में "थ्रो" कीवर्ड का उद्देश्य क्या है?

a) To catch exceptions.

b) To declare a method.

c) To create new objects.

d) To explicitly throw an exception.

Answer: d) To explicitly throw an exception.

 

21. Which Java package provides classes for reading and writing files?

कौन सा जावा पैकेज फाइलों को पढ़ने और लिखने के लिए कक्षाएं प्रदान करता है?

a) java.util

b) java.io

c) java.lang

d) java.file

Answer: b) java.io

 

22. What is the output of the code snippet: System.out.println(7 / 2);?

कोड स्निपेट का आउटपुट क्या है:

a) 3.5

b) 3

c) 2.5

d) 4

Answer: b) 3

 

23. What is the purpose of the "equals" method in Java?

जावा में "बराबर" पद्धति का उद्देश्य क्या है?

a) To compare two objects for reference equality.

b) To compare two objects for value equality.

c) To check if an object is null.

d) To convert an object to a string.

Answer: b) To compare two objects for value equality.

 

24. How do you define a comment that spans multiple lines in Java?

आप जावा में एकाधिक पंक्तियों वाली टिप्पणी को कैसे परिभाषित करते हैं?

a) // This is a comment

b) /* This is a comment */

c) # This is a comment #

d) ' This is a comment '

Answer: b) / This is a comment /

 

25. What is the purpose of the "break" statement in a switch statement?

स्विच स्टेटमेंट में "ब्रेक" स्टेटमेंट का उद्देश्य क्या है?

a) To exit the program.

b) To exit the loop.

c) To exit the switch statement.

d) To print a message.

Answer: c) To exit the switch statement.

 


57 8 months ago