Font size
S
M
L
XL
Worksheets100 MCQ
Total questions: 100
Worksheet time: 33mins
Name
Class
Date
1.
Which keyword is used to define a class in Java?
a)
class
b)
def
c)
struct
d)
ClassDef
2.
Which method is the entry point of any Java program?
a)
start()
b)
main()
c)
execute()
d)
init()
3.
Java was developed by?
a)
Microsoft
b)
Sun Microsystems
c)
Google
d)
IBM
4.
Which extension is used for Java source files?
a)
.jav
b)
.java
c)
.js
d)
.class
5.
Which JVM component converts bytecode into machine code at runtime?
a)
Interpreter
b)
JIT Compiler
c)
Assembler
d)
Loader
6.
Which of these is a primitive data type in Java?
a)
String
b)
Integer
c)
int
d)
Scanner
7.
Default value of boolean variable is:
a)
true
b)
false
c)
0
d)
null
8.
Which keyword is used for defining constants in Java?
a)
const
b)
final
c)
static
d)
constant
9.
Which of these is NOT a feature of Java?
a)
Platform independence
b)
Object-oriented
c)
Pointer arithmetic
d)
Robustness
10.
Which tool is used to compile Java source code?
a)
javac
b)
java
c)
javadoc
d)
jar
11.
Which file is produced after compiling a .java file?
a)
.class
b)
.jar
c)
.exe
d)
.txt
12.
Which command runs a compiled Java program?
a)
javac ClassName
b)
java ClassName
c)
run ClassName
d)
execute ClassName
13.
Which statement is used to print to console in Java?
a)
print()
b)
System.out.print()
c)
console.log()
d)
echo()
14.
Which of the following is correct for a single-line comment in Java?
a)
// comment
b)
/* comment */
c)
<!-- comment -->
d)
# comment
15.
Which package contains the System class?
a)
java.lang
b)
java.util
c)
java.io
d)
java.net
16.
What is JVM?
a)
Java Visual Machine
b)
Java Virtual Machine
c)
Java Versatile Machine
d)
Java Variable Manager
17.
Which of these is platform independent?
a)
Source code
b)
Bytecode
c)
Machine code
d)
Object code
18.
Which tool generates API documentation from Java source?
a)
javac
b)
javadoc
c)
jar
d)
jdb
19.
Which keyword is used to create an object in Java?
a)
create
b)
new
c)
make
d)
construct
20.
Which construct is used to handle exceptions?
a)
try-catch
b)
if-else
c)
for-loop
d)
switch
21.
Which of these is NOT a primitive type?
a)
byte
b)
short
c)
String
d)
long
22.
Which operator is used for logical AND?
a)
&
b)
&&
c)
and
d)
|
23.
Which type stores decimal numbers?
a)
int
b)
float
c)
char
d)
boolean
24.
What is the size of int in Java (bits)?
a)
16
b)
32
c)
64
d)
8
25.
Which wrapper class corresponds to int?
a)
Integer
b)
Int
c)
Number
d)
IntWrapper
26.
Which keyword is used to refer to current object?
a)
self
b)
this
c)
me
d)
current
27.
Which of these converts string to integer?
a)
Integer.parseInt()
b)
Integer.toString()
c)
String.parseInt()
d)
parseInt()
28.
Which operator is used for concatenation of strings?
a)
+
b)
&
c)
concat()
d)
##
29.
What is the default value of reference type instance variable?
a)
0
b)
null
c)
false
d)
undefined
30.
Which is used to find length of an array arr?
a)
arr.length()
b)
arr.length
c)
length(arr)
d)
size(arr)
31.
Which statement is used for conditional branching with multiple choices?
a)
if
b)
if-else
c)
switch
d)
for
32.
Which loop is guaranteed to execute at least once?
a)
for
b)
while
c)
do-while
d)
foreach
33.
Which statement exits a loop immediately?
a)
continue
b)
break
c)
return
d)
exit
34.
Which statement skips remaining loop body and continues next iteration?
a)
break
b)
continue
c)
pass
d)
skip
35.
Which keyword is used to define a method that cannot be overridden?
a)
static
b)
final
c)
private
d)
native
36.
What is output of: System.out.println(5/2);
a)
2
b)
2.5
c)
3
d)
Compilation error
37.
Which is correct way to declare an array of integers?
a)
int[] a = new int[5];
b)
int a = new int[5];
c)
int a[] = new int;
d)
array<int> a = new int[5];
38.
Which control is best for iterating over arrays easily?
a)
for
b)
while
c)
do-while
d)
enhanced for
39.
Which keyword creates a constant variable at class level?
a)
final
b)
static
c)
const
d)
immutable
40.
Which is used to handle multiple exceptions in single catch (Java 7+)?
a)
catch()
b)
multi-catch using |
c)
throws
d)
finally
41.
Which of the following is true about constructors?
a)
Has return type
b)
Same name as class
c)
Inherited
d)
Static
42.
Which keyword is used to inherit a class?
a)
extends
b)
implements
c)
inherits
d)
super
43.
Which are used to declare class-level shared variables?
a)
Instance variables
b)
Local variables
c)
Static variables
d)
Parameters
44.
Which method is called by garbage collector to give an object chance to cleanup?
a)
finalize()
b)
cleanup()
c)
destroy()
d)
dispose()
45.
Which is not a type of constructor?
a)
Default
b)
Parameterized
c)
Copy
d)
Virtual
46.
Which keyword references parent class methods or constructor?
a)
this
b)
super
c)
parent
d)
base
47.
How to declare a method named display returning nothing?
a)
void display()
b)
display void()
c)
function display()
d)
null display()
48.
Which access modifier allows access only within same class?
a)
public
b)
private
c)
protected
d)
default
49.
Which keyword is used to prevent inheritance of a class?
a)
sealed
b)
final
c)
static
d)
abstract
50.
What is default constructor?
a)
Constructor with no args provided by compiler
b)
User defined constructor
c)
Constructor that returns null
d)
Static constructor
51.
Which is true about static methods?
a)
Can access instance vars directly
b)
Cannot access static vars
c)
Belongs to class
d)
Must be overridden
52.
Which of following is true about 'this' keyword?
a)
Used in static methods
b)
Refers to current object
c)
Refers to superclass
d)
Refers to class
53.
Which array is used to hold command-line arguments?
a)
String args
b)
String[] args
c)
char[] args
d)
int[] args
54.
Which class is used to create mutable sequence of characters?
a)
String
b)
StringBuilder
c)
StringBuffer
d)
CharBuilder
55.
Which method appends to StringBuilder?
a)
append()
b)
add()
c)
concat()
d)
push()
56.
Which of these is immutable?
a)
String
b)
StringBuilder
c)
StringBuffer
d)
StringMutable
57.
How to declare a two-dimensional int array?
a)
int[][] a = new int[3][4];
b)
int a[][] = new int[3];
c)
int a[3][4];
d)
int[][] a = int[3][4];
58.
Which keyword is used to create a subclass reference to superclass object?
a)
instanceof
b)
new
c)
super
d)
upcasting
59.
Which is correct way to call a static method show() from same class?
a)
this.show()
b)
ClassName.show()
c)
show.this()
d)
new ClassName().show()
60.
Which class provides utilities like ArrayList, HashMap?
a)
java.lang
b)
java.util
c)
java.io
d)
java.net
61.
Which access modifier allows access within package and subclasses?
a)
public
b)
private
c)
protected
d)
default
62.
Which of these is runtime polymorphism?
a)
Method Overloading
b)
Method Overriding
c)
Constructor Overloading
d)
Operator Overloading
63.
Which of these is compile-time polymorphism?
a)
Method Overloading
b)
Method Overriding
c)
Abstract methods
d)
Interface methods
64.
Which keyword is used to declare an interface?
a)
class
b)
interface
c)
implements
d)
extends
65.
Which class cannot be instantiated?
a)
Concrete class
b)
Abstract class
c)
Regular class
d)
Final class
66.
Which keyword is used to implement multiple inheritance of type?
a)
extends
b)
implements
c)
inherits
d)
super
67.
Which is true about package statement?
a)
Must be last line
b)
Defines namespace and must be first non-comment line
c)
Optional but must be after imports
d)
Cannot be used
68.
Which of these modifiers is accessible only within the same package (no modifier)?
a)
public
b)
private
c)
protected
d)
default (no modifier)
69.
Which operator checks object type at runtime?
a)
typeof
b)
instanceof
c)
is
d)
match
70.
Which of these cannot be overridden?
a)
Instance methods
b)
Static methods
c)
Final methods
d)
Protected methods
71.
Which can contain only abstract methods (before Java 8)?
a)
Class
b)
Interface
c)
Enum
d)
Package
72.
Which keyword is used to prevent method overriding?
a)
static
b)
final
c)
private
d)
native
73.
Which is correct way to declare an enum?
a)
enum Days {MON, TUE}
b)
class Days {MON}
c)
interface Days {MON}
d)
Days = {MON}
74.
Which of these is true about abstract class?
a)
Can be instantiated
b)
May have constructors
c)
Must implement all methods
d)
Cannot have fields
75.
Which keyword is used to declare unchangeable variable?
a)
final
b)
const
c)
immutable
d)
fixed
76.
Which is valid about interfaces in Java 8+
a)
Cannot have any implementation
b)
Can have default and static methods
c)
Cannot have fields
d)
Must be final
77.
Which of these is used for constants grouping?
a)
Interface
b)
Enum
c)
Package
d)
Class
78.
Which keyword used to prevent inheritance of method in subclass?
a)
final
b)
override
c)
static
d)
native
79.
Can an abstract class implement interface without defining methods?
a)
Yes
b)
No
c)
Only if methods are static
d)
Only if class is final
80.
Which statement about enum is true?
a)
Enums are classes
b)
Enums are interfaces
c)
Enums are primitive types
d)
Enums are packages
81.
Which keyword is used to throw an exception manually?
a)
throw
b)
throws
c)
thrown
d)
raise
82.
Which is used to declare that a method may throw exceptions to caller?
a)
throw
b)
throws
c)
throwsException
d)
thrown
83.
Which block always executes after try-catch?
a)
catch
b)
finally
c)
throw
d)
return
84.
Which class is base for checked exceptions?
a)
RuntimeException
b)
Exception
c)
Error
d)
Throwable
85.
Which is an unchecked exception?
a)
IOException
b)
SQLException
c)
NullPointerException
d)
ClassNotFoundException
86.
Which stream reads bytes?
a)
Reader
b)
InputStream
c)
BufferedReader
d)
FileReader
87.
Which stream reads characters?
a)
InputStream
b)
FileInputStream
c)
Reader
d)
BufferedInputStream
88.
Which class writes characters to a file?
a)
FileOutputStream
b)
FileWriter
c)
BufferedInputStream
d)
DataInputStream
89.
Which class is used for buffered character input?
a)
BufferedReader
b)
BufferedInputStream
c)
BufferedWriter
d)
FileWriter
90.
Which class is used to write bytes to file?
a)
FileWriter
b)
FileOutputStream
c)
BufferedReader
d)
FileReader
91.
Which collection allows duplicate elements and maintains insertion order?
a)
HashSet
b)
TreeSet
c)
ArrayList
d)
Hashtable
92.
Which interface represents a key-value mapping?
a)
List
b)
Set
c)
Map
d)
Collection
93.
Which class is synchronized and thread-safe for lists?
a)
ArrayList
b)
Vector
c)
LinkedList
d)
CopyOnWriteArrayList
94.
Which keyword creates a new thread by extending thread class?
a)
implements Runnable
b)
extends Thread
c)
new Thread()
d)
start()
95.
Which method starts a thread's execution?
a)
run()
b)
start()
c)
execute()
d)
init()
96.
Which wrapper type corresponds to boolean?
a)
Boolean
b)
Bool
c)
boolean
d)
BoolWrapper
97.
Which method converts integer to string?
a)
Integer.toString()
b)
toStr()
c)
String.valueOf()
d)
parseInt()
98.
Which collection class stores key-value pairs and allows null keys?
a)
Hashtable
b)
HashMap
c)
TreeMap
d)
ConcurrentHashMap
99.
Which package contains collections framework interfaces?
a)
java.io
b)
java.lang
c)
java.util
d)
java.net
100.
Which operator is used to compare object references?
a)
Zero
b)
equals()
c)
compareTo()
d)
equalsIgnoreCase()
Reset
