Top Java Interview Questions and Answers 2022 | Best MCQ Type Java Interview Questions and Answers For Freshers

Top Java Interview Questions and Answers 2022 | Best MCQ Type Java Interview Questions and Answers For Freshers

Top Java Interview Questions and Answers 2022 | Best MCQ Type Java Interview Questions and Answers For Freshers

Quiz NameJava Interview Questions and Answers
Number of Questions30
Time30 Minutes
Exam TypeMCQ (Multiple Choice Questions)

1. Which statement transfers execution to different parts of your code based on the value of an expression?
a. Nested-if
c. If
d. Switch

2.Which of the following creates an instance of an anonymous inner class?
a. new Runnable();
b. new Runnable(public void run());
c. new Runnable r = public void run();
d. System.out.println(new Runnable() public void run());

3. Which of the following isn't a characteristic of Java?
a. Dynamic
b. Neutral in architecture
c. Pointers are used.
d. Object-oriented

4.Which of the following choices is better for generating a random integer 0 or 1?
a. (int)Math.random()
b. (int)Math.random() + 1
c. (int)(Math.random() + 0.5)
d. (int)(Math.random() + 0.2)

5. Which of the following is the proper expression if the number x is between 1 and 100 or is negative?
a. 1 x 100 || x 0 A.
b. ((x 100) and (x > 1)) || (x 0)
c. ((x 100) && (x > 1)) && (x 0)
d.(1 x > 100) || (x 0)

6. How many Constructor String classes are there?
a. 2
b. 7
c. 13
d. 11

7. What does the following code produce: public class Examination main(String[] args) public static void main(String[] args) x = 120, 200, 016; int[] x = 120, 200, 016; System.out.print(x[i] + " "); for(int I = 0; I x.length; i++)
a. 140 120 200 14
b.1220 0016
c.The number 016 is a compilation error. It should be written as 16 instead.
d. 160 200 120

8. Assume a class is visible to the general public. We define a protected method in this class. Which one of the following statements is true?
a. This method is only accessible from within the class and all of its subclasses.
b. You cannot specify methods in a class that have a lower visibility than the visibility of the class in which it is declared.
c. You cannot access public methods from within protected methods.
d. This function is available from within the class as well as from any classes declared in the same package as the class.

9. Which of the following automatic type conversions will be possible?
a. short to int
b. byte to int
c. int to long
d. long to int

10.Which of the following statements is true?
a.The replace() method replaces all occurrences of one character in the invoking string with another character.
b. The replace() function replaces only the initial occurrences of a character in an invoking string with another character.
c. The replace() method replaces all of the characters in the invoking string with another character.
d.replace() The replace() method replaces the last occurrence of a character in the invoking string with another character.

11. Which of the following is a method of wrapper Float for converting an object's value to byte?
a. the bytevalue ()
b. byte bytevalue ()
c. Bytevalue ()
d. Byte Bytevalue ()

12. Which of these keywords does not belong to exception handling?
a. try
b. eventually

13. Which of the following is a bad array declaration? arr[] = new int[5]
b. [] int new int[5] = arr
c. int arr[]arr = new int[5] C. int arr[]arr = new int[5]
d. int arr[] = new int [5]

14. Which of these can use the modulus operator, percent?
a. Integers
b. Floating – point numbers
c. Both integers and floating-point numbers.
d.none of the preceding

15.Which of these processes is handled automatically by the Java runtime system?
a. Serialization
b. Garbage collection
c. Filtering of Files
d. All of the aforementioned

16.Which of the following methods can be used to manually increase the capacity of an ArrayList object?
a. Capacity ()
b. Increase Capacity ()
c. enhance capacity ()
d. ensureCapacity ()

17.Which of the following is a type of stream in Java?
a. Integer stream
b. A short stream
c. Byte Stream
d. A long stream

18. Which of these packages contains all of the collection classes?
a. java.lang is an abbreviation for Java.
b. java.util
d. java.awt

19.Which of these functions is used to display the output of an applet?
a. show ()
b. print ()
c. displayApplet ()
d. PrintApplet ()

20.Which of these methods can be used to have the main thread run last among all the threads?
a. pause ()
b. sleep ()
c. join ()
d. phone call ()

21. Which of these literals can be stored in a data type float variable?
a. 1.7e-308
d. 3.4e-050

22. In Java, a thread can be created via............
a. Extending the Thread class
b.Implementing the Runnable interface.
c. Both of the preceding
d. none of the above

23.Which of the following statements about constructors is true? 1. A class may have more than one function Object() { [native code] }. 2. They can be inherited. 3. Their address can be referenced to. 4. Constructors cannot be declared in the protected part of the class. 5. Constructors cannot return values.
a. Only 1,2,4
b. 1,2,4,5

24. Which of the following allows for the storage of a null key and null values?
b. HashMap
c. none of the preceding
d. Collections

25. Which of the following has the method flush()?
a. Input stream
b. The readership
c. Reader stream input
d. Output Stream

26.What are some Application Server examples?
a. Tomcat
b. JBoss
c. Weblogic
d. Both C and D are correct.

27. A condition in which two or more threads are perpetually stalled and waiting for each other to release resources.
a. Crucial Section
b. Mutual Exclusion
d. Impasse

28. The following example demonstrates whether XML Syntax rule, noting date=" 12/11/2007′′> to> Tove /from> Jani /from> /note>
a. XML Attribute Values Must Be Quoted
b. All XML Elements Require a Closing Tag
c. XML Tags Are Case Sensitive
d. XML Elements Must Be Properly Nested

29. In Java, how many instances of the Singleton class may there be?
a. It is dependent on the calling application.
b. Is dependent on the class that creates the object of the Singleton class.
d. 1

30.import java.util.*; public class Main public static void main (String[] args) { \sList mylist = new ArrayList(); mylist.remove(0); System.out.println(mylist.size());
a. Nothing is printed.
b. 0
c. IndexOutOfBoundsException