Top Java MCQ
Top Java MCQ
Home » MCQs
Java MCQs: This section contains multiple-choice questions and answers on Java
programming language. It will help the students and developers to prepare well for their
exams, and enhance their skills.
Explanation:
JDK stands for Java Development Kit. It is a platform to develop and run Java applications.
Explanation:
JRE stands for Java Runtime Environment which provides an environment to run a java
program.
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 1/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
In Java, programs are compiled into byte code and that byte code is platform-independent.
4. Can we keep a different name for the java class name and java file name?
A. Yes
B. No
Answer: A) Yes
Explanation:
Yes, we can keep different names for java filename and java class name if and only if the
class is not public.
A. Heap memory
B. Stack memory
C. Both A and B
D. None of these
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 2/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Memory allocation in java occurs in two ways, mainly, stack and heap space.
A. //
B. /* */
C. <!-- -- >
D. All of these
Answer: B) /* */
Explanation:
Multi-line comments start with /* and ends with */ . Any text between /* and */ will be
ignored by Java.
A. main() method
B. The first line of code
C. Last line of code
D. main class
Explanation:
Generally, the main() method is treated as the point where the flow of code starts.
A. Yes
B. No
Answer: A) Yes
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 3/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
Yes, we can write a java program without the main() method but there is a condition if and
only if java JDK version till JDK 5.
A. Yes
B. No
Answer: A) Yes
Explanation:
Yes, We can overload the main method in java but JVM only calls the original main method,
it will never call our overloaded main method.
A. exep
B. excepHand
C. throw
D. All of these
Answer: C) throw
Explanation:
11. Which class in Java is used to take input from the user?
A. Scanner
B. Input
C. Applier
D. None of these
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 4/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Answer: A) Scanner
Explanation:
The Scanner class is used to get user input, and it is found in the java. util package.
A. next()
B. nextLine()
C. Both A. and B.
D. None of these
Explanation:
The next() method can read the input only till the space. It can't read two words separated
by space, while the nextLine() reads input including space between the words (that is, it
reads till the end of line \n ).
13. Which of the following is the correct syntax to create a variable in Java?
A. var name;
B. int name;
C. var name int;
D. All of these
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 5/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
A. Yes
B. No
Answer: B) No
Explanation:
String in Java is immutable i.e., once defined the value cannot be changed.
A. Instance Variable
B. Local Variable
C. Static Variable
D. All of these
Explanation:
1. Instance variable
2. Local variable
3. Class/Static variable
Copy
A. Hello
B. Bye
C. Error
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 6/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
D. All of these
Answer: B) Bye
Explanation:
Type casting is when you assign a value of one primitive data type to another type.
A. Widening typecasting
B. Narrowing typecasting
C. Manual typecasting
D. All of these
Explanation:
A. Class
B. Method
C. Variable
D. All of these
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 7/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
A. Try-catch block
B. Class block
C. Method block
D. All of these
Explanation:
Explanation:
The break statement in Java is used to terminate from the loop immediately.
Copy
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 8/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
A. 1
B. No output
C. 8
D. 1357911
Answer: B) No output
Explanation:
23. Can the Java program accept input from the command line?
Explanation:
In Java, we can also provide values (arguments) while calling the program through the
command line. These arguments are known as Command Line Arguments.
Explanation:
Explanation:
A. Classes
B. References
C. Iterators
D. None of these
Answer: B) References
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 10/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
Garbage collection in Java is the process by which Java programs perform automatic
memory management.
A. final variables
B. new variables
C. Constants
D. All of these
Answer: C) Constants
Explanation:
The static variables declarations just like constants, they required static keyword and an
initial value.
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 11/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
All of the above points are correct with respect to a BigInteger class.
Explanation:
Java this keyword is used to hold the reference of the current object.
Copy
import java.util.Scanner;
class ThisKeyword {
private int a = 4;
private int b = 1;
A. 5
B. 9
C. 8
D. 4
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 12/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Answer: C) 8
Explanation:
The above Java program is an example to demonstrate the use of this keyword.
Explanation:
The super keyword refers to superclass (parent) objects. It is used to call superclass
methods, and to access the superclass constructor.
Explanation:
In Java programming language, the super() is a reference variable that is used to refer parent
class constructors. The super can be used to call parent class's variables and methods. The
super() can be used to call parent class' constructors only.
Explanation:
A Wrapper class is a class whose object wraps or contains primitive data types.
Explanation:
In Java programming language, the wrapper classes are those whose objects wraps a
primitive data type within them. The wrapper class is used for converting primitive datatype
to object is called boxing.
Explanation:
An abstract class is a class that contains an abstract method. It is defined using abstract
keyword only has method declarations and to use these methods, the abstract class needs
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 14/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
to be inherited.
Explanation:
File handling is used for creating, deleting, and modifying files using a java program.
A. Java.files
B. Java.io
C. Java.io.File
D. Java.FileHandling
Answer: C) Java.io.File
Explanation:
A. C:\Program Files\Java\jdk1.8.0_131\bin\file_name.txt
B. C:\Program Files\Java\file_name.txt
C. C:\Program Files\Java\jdk1.8.0_131\file_name.txt
D. C:\Program Files\Java\jdk1.8.0_131\bin\File Handling\file_name.txt
Explanation:
C:\Program Files\Java\jdk1.8.0_131\bin\file_name.txt
A. file.addLine()
B. file.nextLine()
C. file.write()
D. file.line()
Answer: C) file.write()
Explanation:
A. file.delete()
B. file.remove()
C. file.garbage()
D. file.dump()
Answer: A) file.delete()
Explanation:
A. file.read()
B. file.nextLine()
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 16/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
C. file.getLine()
D. All of these
Answer: C) file.getLine()
Explanation:
43. The correct syntax to import the math library in java is ___.
A. import java.lang.math
B. import math
C. import java.math
D. All of these
Explanation:
import java.lang.math
A. max()
B. cbrt()
C. log10()
D. All of these
Explanation:
Some common methods of the math library are max() , min() , cbrt() , pow() , log() ,
log10() , etc.
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 17/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
A. random.nextInt()
B. random()
C. rand()
D. All of these
Answer: A) random.nextInt()
Explanation:
A. Method
B. A process allowing methods to call itself
C. The process to call methods
D. None of these
Explanation:
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 18/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
A. Array
B. List
C. Vector
D. All of these
Explanation:
All of the above (Array, List, and Vector) are valid data structures in Java.
A. Vector < string > names = new Vector < String > ();
B. Vector name = new string;
C. int name = new vector ()
D. All of these
Answer: A) Vector < string > names = new Vector < String > ();
Explanation:
The hex2bin() function is used to convert hexadecimal values to the ASCII characters.
Vector < string > names = new Vector < String > ();
Copy
import java.util.Scanner;
class ThisKeyword {
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 19/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
private int a = 4;
private int b = 1;
A. Error
B. 8
C. 5
D. None of these
Answer: B) 8
Explanation:
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 20/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
A. createString()
B. toString()
C. object.string()
D. newString()
Answer: B) toString()
Explanation:
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 21/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
A. compare()
B. equate()
C. isEqual()
D. All of these
Answer: A) compare()
Explanation:
compare()
equals()
56. Which of the following statements is not correct for vectors in Java?
Answer: C) It is asynchronous
Explanation:
Copy
public class Main {
public static void main(String[] args) {
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 22/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
A. Error
B. include
C. help
D. Includehelp
Answer: D) Includehelp
Explanation:
The string here is a StringBuffer hence the contents can be edited which makes the append
method work on it by adding 'help' to the end of the string.
A. State when all processes have complete working and are dead
B. State when threads are in hold state forever
C. State when threads are not ready
D. All of these
Explanation:
Deadlock in Java is a condition when two or more threads try to access the same resources
at the same time.
A. Deadlock graph
B. Time graph
C. Wait-for-graph
D. None of these
Answer: C) Wait-for-graph
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 23/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
A. Used to execute a group of queries or a batch as executing a single query, again and
again, is time taking and reduce the performance
B. Used to processing multiple queries can be executed at once
C. Used to increase program's performance
D. All of these
Explanation:
A. Reserved keyword
B. Literal value
C. Used in exception handling
D. All of these
Explanation:
All of the mentioned points are true about the Null in Java.
D. None of these
Explanation:
In Java, the Enumeration is a data type which contains a fixed set of constants, they are used
to create our own data type like classes.
A. Yes
B. No
Answer: A) Yes
Explanation:
64. Which of the following ways is the correct way to create an object in Java?
Explanation:
All of the above-mentioned ways are the correct way to create an object Java.
There are five different ways to create an object and we will see the ways to create an
object given below:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 25/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
A. extends
B. inheritance
C. isChild
D. None of these
Answer: A) extends
Explanation:
A. Single
B. Multiple
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 26/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
C. Multi-level
D. Hierarchical
Answer: B) Multiple
Explanation:
Explanation:
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 27/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
Java packages are the ways to encapsulate a group of classes, sub-packages, and interface.
A. Marker interface
B. Abstract class
C. Derived class
D. None of these
Explanation:
A. public
B. private
C. native
D. All of these
Answer: C) native
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 28/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
Explanation:
In Java, the boolean keyword is a primitive data type. It is used to store only two possible
values, either true or false.
A. equals() method
B. hashCode() method
C. toString() method
D. All of these
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 29/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
All are valid Boolean class methods. Some common methods are equals(), hashCode(),
toString(), valueOf(), etc.
A. isNan()
B. checkNan()
C. isNotNan()
D. All of these
Answer: A) isNan()
Explanation:
Explanation:
The multiple threads can be executed concurrently and it has own property.
A. New thread
B. User-created thread
C. Daemon thread
D. All of these
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 30/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
Explanation:
Multithreaded programming a process in which two or more parts of the same process run
simultaneously.
Copy
A. 100.6
B. -100.6
C. -200.6
D. 200.6
Answer: B) -100.6
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 31/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
The Math.copySign() returns the first floating-point argument with the sign of the second
floating-point argument.
A. convertRadtoDeg()
B. toDegrees()
C. degree()
D. All of these
Answer: B) toDegrees()
Explanation:
82. Which of the following methods is used to extract the length of a string in Java?
A. length()
B. len()
C. sizeof()
D. size()
Answer: A) length()
Explanation:
The Java method length() is used to extract the length of a string in Java.
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 32/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
The Java method trim() is a built-in function that eliminates leading and trailing spaces.
Explanation:
Java Regular Expressions or Regex is an API for defining String patterns that can be used for
searching, manipulating, and editing a string.
A. Data structure
B. Defined in java.util package
C. Represented using key-value pairs
D. All of these
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 33/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
Copy
import java.util.Hashtable;
System.out.println(ht);
}
}
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 34/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
A. Hashtable
B. Map
C. Array
D. None of these
Answer: A) Hashtable
Explanation:
A. deleteAll()
B. delete()
C. clearAll()
D. clear()
Answer: D) clear()
Explanation:
The clear() method of ArrayList in Java is used to remove all the elements from a list.
90. Which Java method is used to add all of the specified elements to the specified
collection?
A. addValue()
B. copy()
C. cpy()
D. addAll()
Answer: D) addAll()
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 35/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
Explanation:
The addAll() method of java.util.Collections class is used to add all of the specified
elements to the specified collection.
91. Which Java method is used to detect the OS in which Java program is being run?
A. system.getOSdetails()
B. system.get(os.name)
C. system.getProperties("os.name")
D. system.getProperties("os")
Answer: C) system.getProperties("os.name")
Explanation:
A. UTF-32
B. UTF-16
C. UTF-12
D. Based on the host platform
Explanation:
93. Which method in java is used to get the name of running java VM?
A. System.getProperties("java.vm.name")
B. System.vmName
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 36/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
C. Sytem.getVmName
D. System.getProperties("vm.name")
Answer: A) System.getProperties("java.vm.name")
Explanation:
94. Which Java method is used to get the version of running java VM?
A. System.vm.version
B. System.getProperties("vm.version")
C. System.getProperties("java.vm.version")
D. System.getVmVersion
Answer: C) System.getProperties("java.vm.version")
Explanation:
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 37/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
A. /w
B. /c
C. /str
D. /?
Answer: A) /w
Explanation:
A. Java ARchive
B. Java application runtime
C. Java application runner
D. None of these
Explanation:
A. get
B. import
C. extends
D. All of these
Answer: B) import
Explanation:
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 38/41
10/22/24, 11:01 PM Top 100 Java Multiple-Choice Questions (MCQs) and Answers
A. Error
B. Expectation
C. Infinite
D. None of these
Answer: B) Expectation
Explanation:
Copy
A. includehelp
B. include
C. help
D. None of these
Answer: A) includehelp
Explanation:
In the above code, the "+" operator is concatenating both of the strings.
https://www.includehelp.com/mcq/java-multiple-choice-questions-mcqs.aspx 39/41