Java Basics - Multiple Choice Questions (MCQs)
Java Basics
Which of the following is a valid Java identifier?
Answer: C) _value
Java is:
Answer: C) Both compiled and interpreted
Which method is the entry point of a Java program?
Answer: B) main()
What does JVM stand for?
Answer: A) Java Virtual Machine
What is bytecode in Java?
Answer: C) Intermediate code between source and machine
Data Types and Variables
Which is not a primitive type in Java?
Answer: C) String
What is the default value of an int variable?
Answer: A) 0
Which keyword is used to define a constant?
Answer: A) final
Which of these is not a valid data type in Java?
Answer: B) real
Which wrapper class is used for the primitive type int?
Answer: A) Integer
Operators
What is the result of 10 + 20 + "Java"?
Answer: A) 30Java
Which operator is used to compare two values?
Answer: B) ==
What is the output of true && false?
Answer: B) false
Which operator is used for bitwise AND in Java?
Answer: B) &
What is the use of the ternary operator (? :) in Java?
Answer: B) Condition
Control Structures
Which statement is used for decision-making?
Answer: A) if
The switch statement works with:
Answer: D) All of the above
Which keyword is used to exit from a loop?
Answer: B) break
Which keyword is used to skip one iteration of a loop?
Answer: B) continue
Which loop executes at least once?
Answer: C) do-while
Loops
Which loop is best when the number of iterations is known?
Answer: C) for
What is the output of for(int i=0;i<3;i++) [Link](i);
Answer: B) 012
What is the default increment step in a for loop?
Answer: C) 1
Can you nest one loop inside another in Java?
Answer: B) Yes
What is the output of this code? while(false){}
Answer: C) No output
Arrays and Strings
How do you declare an array in Java?
Answer: B) int array[];
Which of the following is the correct way to initialize an array?
Answer: A) int a[] = {1, 2, 3};
What is the index of the first element in an array?
Answer: C) 0
Which method is used to find the length of a string?
Answer: A) length()
What will "Java".charAt(0) return?
Answer: A) J
Object-Oriented Concepts
Which of the following is a class?
Answer: A) public class Car {}
What is an object in Java?
Answer: C) An instance of a class
Which keyword is used to create an object?
Answer: B) new
What is encapsulation?
Answer: B) Hiding data
Which of the following is used to inherit a class?
Answer: C) extends
Miscellaneous
Which of these is not an access modifier?
Answer: D) package
What is the file extension for Java source files?
Answer: B) .java
Which method is used to start a thread?
Answer: B) start()
Which package is automatically imported in every Java program?
Answer: C) [Link]
Which of the following is not part of OOP principles?
Answer: D) Compilation
Input/Output & Exceptions
Which class is used for input from the user?
Answer: A) Scanner
What package do you import for Scanner?
Answer: B) [Link]
Which method of Scanner reads an integer?
Answer: A) nextInt()
What is exception handling used for?
Answer: A) Managing errors
Which block is always executed in exception handling?
Answer: C) finally
Advanced Basic
Which keyword is used to inherit an interface?
Answer: B) implements
What is method overloading?
Answer: A) Using the same method name with different parameters
What is the use of this keyword?
Answer: B) Refers to the current object
Which of the following is not a loop structure in Java?
Answer: D) repeat
What does public static void main mean?
Answer: C) Main method can be called without object