wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Sothanaigal 2.0

Total questions: 16

Worksheet time: 13mins

Name
Class
Date
1.

Java saw this code and laughed. Why? 😄

int age = 18;

if(age = 18)

System.out.println("Eligible");

a)

Not Eligible will print

b)

Assignment used instead of comparison

c)

age is too young

d)

Eligible

2.

Java drank coffee ☕ and executed:

int x = 5;

System.out.println(x++ + x++ + ++x);

a)

18

b)

19

c)

20

d)

21

3.

Java asks: “Who comes first?” 🤨

int x = 10;

System.out.println(++x * x++);

a)

110

b)

121

c)

120

d)

Error

4.

This loop escaped from jail 🏃‍♂️

for(int i=1; i<=5; i--)

System.out.print(i);

a)

12345

b)

54321

c)

Infinite loop

d)

Compile Error

5.

Java got emotionally confused 😵

String s1 = "Java";

String s2 = "Java";

System.out.println(s1 == s2);

a)

true

b)

false

c)

error

d)

Depends

6.

Java asks: “Who am I?” 🤔

class Test {

int x;

}

-->x is:

a)

Object

b)

Method

c)

Instance variable

d)

Class

7.

int x = 0;

if(x++ == 0 && ++x == 2)

System.out.println("True");

else

System.out.println("False");

Output?

a)

True

b)

False

c)

Error

d)

Nothing

8.

for(int i=1;i<=3;i++)

{

for(int j=1;j<=i;j++)

System.out.print(j);

}

a)

123

b)

112123

c)

121

d)

123123

9.

int i = 1;

System.out.print(i++ + ++i);

a)

3

b)

4

c)

5

d)

6

10.

Which one makes Java say “I don’t know what to do” 😵?

a)

Infinite loop

b)

Ambiguous method call

c)

Array out of bound

d)

All of the above

11.

Java said: “I am very secure 🔐”. Why?

a)

It uses antivirus

b)

It has strong password

c)

It uses Encapsulation

d)

It hides from hackers

12.

Why did the Java loop break up with the condition? 💔

a)

Condition was false

b)

Infinite relationship

c)

No increment

d)

All of the above

13.

Java’s garbage collector does which job? 🧹

a)

Deletes unused memory

b)

Cleans your PC

c)

Deletes bugs

d)

Makes program faster always

14.

What happens if a program has no logic, but no syntax error?

a)

Program fails

b)

Compile error

c)

Wrong output

d)

Program doesn’t run

15.

int a = 5; // 0101

int b = 3; // 0011

System.out.println(a & b);

a)

1

b)

3

c)

7

d)

5

16.

Draw an array as a train 🚂