NEW
Font size
S
M
L
XL
WorksheetsCC102 - JAVA FINAL EXAM
Total questions: 60
Worksheet time: 30mins
Name
Class
Date
1.
Which keyword is used to test a condition in Java?
a)
test
b)
if
c)
case
d)
check
2.
Which symbol means "equal to" in a condition?
a)
=
b)
!=
c)
==
d)
<=
3.
What will be the output?
int x = 8; if (x > 10) System.out.print("A"); else System.out.print("B");
a)
A
b)
B
c)
AB
d)
No output
4.
Which statement allows checking multiple conditions in sequence?
a)
if
b)
if-else-if
c)
for
d)
while
5.
Which keyword is optional in an if statement?
a)
if
b)
else
c)
switch
d)
break
6.
Which logical operator represents OR?
a)
&&
b)
!
c)
||
d)
==
7.
What will be printed?
int a = 5; int b = 3; if (a > b && b > 0) System.out.print("Yes");
a)
No
b)
Yes
c)
Error
d)
Nothing
8.
Which conditional statement uses case labels?
a)
if
b)
while
c)
for
d)
switch
9.
Which data type is commonly used in conditions?
a)
int
b)
boolean
c)
double
d)
char
10.
Which symbol represents NOT?
a)
!
b)
&&
c)
||
d)
==
11.
What happens if no case matches in a switch statement?
a)
Error occurs
b)
Program stops
c)
default executes
d)
First case executes
12.
Which statement is true?
a)
else must always be used
b)
if cannot stand alone
c)
if can exist without else
d)
switch replaces if completely
13.
Which loop runs at least once?
a)
for
b)
while
c)
do-while
d)
foreach
14.
How many times will this loop execute?
for(int i = 0; i < 4; i++) System.out.print(i);
a)
3
b)
4
c)
5
d)
Infinite
15.
Which keyword stops a loop completely?
a)
stop
b)
continue
c)
break
d)
exit
16.
Which loop is best when the number of iterations is known?
a)
while
b)
do-while
c)
for
d)
switch
17.
What does continue do?
a)
Ends the program
b)
Skips the current iteration
c)
Ends the loop
d)
Repeats the loop forever
18.
Which loop condition is checked after execution?
a)
for
b)
while
c)
do-while
d)
foreach
19.
Which loop is used to traverse arrays easily?
a)
for
b)
while
c)
do-while
d)
enhanced for
20.
What will be the output?
int i = 1; while(i <= 3){ System.out.print(i); i++; }
a)
123
b)
12
c)
321
d)
Error
21.
Which keyword is used to skip to the next iteration?
a)
break
b)
stop
c)
continue
d)
pass
22.
Which loop may not execute at all?
a)
for
b)
do-while
c)
foreach
d)
all loops
23.
Which loop is best when condition depends on user input?
a)
for
b)
while
c)
switch
d)
if
24.
Which loop uses initialization, condition, and increment together?
a)
while
b)
do-while
c)
for
d)
foreach
25.
Which index does an array start with in Java?
a)
-1
b)
0
c)
1
d)
Depends on size
26.
Which is the correct array declaration?
a)
int arr;
b)
int arr[] = new int[5];
c)
array int arr;
d)
int arr = 5;
27.
What is the output?
int[] n = {2,4,6}; System.out.print(n[2]);
a)
2
b)
4
c)
6
d)
Error
28.
Which property gives array length?
a)
size
b)
count
c)
length
d)
total
29.
What happens if index is out of bounds?
a)
Program ignores it
b)
Compilation error
c)
Runtime error
d)
Logical error
30.
Which loop is commonly used with arrays?
a)
if
b)
switch
c)
for
d)
try
31.
How many elements does this array have?
int[] a = new int[7];
a)
6
b)
7
c)
8
d)
Undefined
32.
Which array stores characters?
a)
int[]
b)
char[]
c)
double[]
d)
boolean[]
33.
Which statement accesses the first element?
a)
arr[1]
b)
arr[0]
c)
arr[first]
d)
arr[-1]
34.
Which array type stores true or false values?
a)
int[]
b)
String[]
c)
boolean[]
d)
char[]
35.
Which keyword creates an array object?
a)
array
b)
create
c)
new
d)
make
36.
Which exception occurs when accessing invalid index?
a)
NullPointerException
b)
IOException
c)
ArrayIndexOutOfBoundsException
d)
ClassNotFoundException
37.
What is a class?
a)
An object
b)
A blueprint of objects
c)
A method
d)
A variable
38.
Which keyword creates an object?
a)
class
b)
object
c)
new
d)
this
39.
Which concept hides data from direct access?
a)
Inheritance
b)
Polymorphism
c)
Encapsulation
d)
Abstraction
40.
Which access modifier is most restrictive?
a)
public
b)
protected
c)
default
d)
private
41.
Which keyword is used for inheritance?
a)
inherit
b)
extends
c)
implements
d)
super
42.
Which concept allows method overriding?
a)
Encapsulation
b)
Polymorphism
c)
Abstraction
d)
Interface
43.
Which is an example of abstraction?
a)
Variables
b)
Methods
c)
Abstract classes
d)
Objects
44.
Which keyword refers to the current object?
a)
this
b)
super
c)
static
d)
final
45.
Which method has the same name as the class?
a)
main
b)
constructor
c)
setter
d)
getter
46.
What is polymorphism?
a)
One class only
b)
Many forms of a method
c)
Hiding data
d)
Code duplication
47.
Which concept promotes code reusability?
a)
Encapsulation
b)
Inheritance
c)
Abstraction
d)
Polymorphism
48.
Which keyword prevents inheritance?
a)
static
b)
final
c)
abstract
d)
private
49.
Which component displays text only?
a)
JTextField
b)
JLabel
c)
JButton
d)
JCheckBox
50.
Which component accepts text input?
a)
JLabel
b)
JButton
c)
JTextField
d)
JOptionPane
51.
Which component shows dialog boxes?
a)
JFrame
b)
JLabel
c)
JOptionPane
d)
JPanel
52.
Which component triggers an action when clicked?
a)
JLabel
b)
JButton
c)
JTextField
d)
JRadioButton
53.
Which component allows multiple selections?
a)
JRadioButton
b)
JButton
c)
JCheckBox
d)
JLabel
54.
Which component allows only one selection in a group?
a)
JCheckBox
b)
JButton
c)
JRadioButton
d)
JLabel
55.
Which class groups radio buttons together?
a)
JPanel
b)
ButtonGroup
c)
JFrame
d)
Container
56.
Which Swing package contains GUI components?
a)
java.awt
b)
java.util
c)
javax.swing
d)
java.io
57.
Which method shows a message dialog?
a)
setText()
b)
showMessageDialog()
c)
getText()
d)
add()
58.
Which component is used to get user confirmation?
a)
JLabel
b)
JTextField
c)
JOptionPane
d)
JButton
59.
Which layout arranges components in a grid?
a)
FlowLayout
b)
BorderLayout
c)
GridLayout
d)
CardLayout
60.
Which event occurs when a button is clicked?
a)
KeyEvent
b)
MouseEvent
c)
ActionEvent
d)
WindowEvent
Reset
