wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java - Quiz 3

Total questions: 24

Worksheet time: 18mins

Name
Class
Date
1.

What is the correct output?

a)

a) true

true

false

true

b)

b) true

false

true

true

c)

c)false

false

true

true

d)

d)false

true

true

false

2.

condition ? expression1 : expression2;

if condition is true, expression2 is executed.

a)

a) true

b)

b) false

3.

PREDICT THE OUTPUT:

int x = 60;

int y = 90;

if (y%x == 0 && y-x==30){

System.out.println("Hello World"); }

else{

System.out.println("Error"); }

a)

a) Hello World

b)

b) Error

c)

c) Hello world

d)

d) Hello World

Error

4.

When the variable being switched on is equal to a case, the statements following that case will execute until a _ statement is reached.

a)

a) continue;

b)

b) break;

c)

c) default;

d)

d) go;

5.

Which data types are allowed in a Java switch statement?

a)

a) int, short, byte, double, char

b)

b) String, int, short, char

c)

c) char, byte, short, int, String

d)

d) String, int, byte

6.

What option describes button number 5 on the toolbar?

a)

a) Step over an expression

b)

b) Step over

c)

c) Step into

d)

d) Step out of

7.

which is the Default format of LocalDateTime?

a)

a) 2014-04-28

b)

b) 2014-04-28T23:25:49.342Z

c)

c) 2014-04-28T16:25:49.341

d)

d) 28::Apr::2014

8.

int [ ] [ ] numbers = new int [ 8 ][ 7 ]

which option is correct?

a)

a) 7 arrays of 8 elements each

b)

b) 8 arrays of 7 elements each

9.

How many times will the following code print "Welcome to Java"?

int count = 0;

while (count < 10) {  

System.out.println("Welcome to Java");  

count++; }

a)

a) 11

b)

b) 9

c)

c) 8

d)

d) 10

10.

What is the output of the following code?

int x = 0;

while (x < 4) {

 x = x + 1; }

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

a)

a) x is 3

b)

b) x is 2

c)

c) x is 4

d)

d) x is 0

11.

The following loop displays _.

for (int i = 1; i <= 10; i++) {  

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

i++; }

a)

a) 1 2 3 4 5 6 7 8 9

b)

b) 1 2 3 4 5 6 7 8 9 10

c)

c) 1 3 5 7 9

d)

d) 1 2 3 4 5 

12.

How many times is the println statement executed?

for (int i = 0; i < 10; i++)   

for (int j = 0; j < 10; j++)  

System.out.println(i * j);

a)

a) 10

b)

b) 100

c)

c) 1

d)

d) 1000

13.

What will be displayed when the following code is executed?  

int number = 6;  

while (number > 0) {  

number -= 3;  

System.out.print(number + " ");  }

a)

a) 6 3

b)

b) 3 3

c)

c) 6 6

d)

d) 3 0

14.

What is the correct function of a while loop?

a)

a) To consume the initialization, condition and increment/decrement in one line

b)

b) To check for condition after executing the statements

c)

c) A control flow statement that allows code to be executed repeatedly based on a given Boolean condition.

d)

d) To initialize the variable in use.

15.
a)

a) Compilation error

b)

b)"Loop" will be printed infinite times

c)

c) "Loop" will be printed once

d)

d) No output

16.

which is correct order?

1- Use to iterate indefinitely through statements and to perform the statements zero or more times.

2- Use to iterate through the elements of an Array or ArrayList.

3- Use to iterate indefinetely through statements and to perform the statements one or more times.

4- Use to step through statements a predefined number of times.

a)

a) 1- do/while

2-enhanced for

3-while

4-for

b)

b) 1- do/while

2-while

3-for

4-enhanced for

c)

d) 1-for

2- do/while

3-enhanced for

4-while

d)

d) 1-while

2-enhanced for

3-do/while

4-for

17.

Which is correct?

a) ArrayList<int> arrayList = new ArrayList<>();

b) ArrayList<Integer> arrayList = new ArrayList<>();

a)

a)

b)

b)

18.
a)

a) I eat dog food

I can bark

b)

b) I can eat

I can bark

19.

is a class which inherits the other class

a)

a) Super Class

b)

b) Sub Class

c)

c) Class

20.

Is when a subclass implements a method that already has an implementation in the superclass

a)

a) extends

b)

b) inheritance

c)

c) overriding

d)

d) hierarchy

e)

e) polymorphism

21.

Represents the IS-A relationship

a)

a) Polymorphism

b)

b) Inheritance

c)

c) Reusability

d)

d) Hierarchy

22.

An interface is a kind of template for building classes.

Can a class implement one or more interfaces?

a)

a) true

b)

b) false

23.

What are the valid statements for static keyword in Java?

a)

a) We can have static block in a class.

b)

b) The static block in a class is executed every time an object of class is created.

c)

c) We can have static method implementations in interface.

d)

d) We can define static block inside a method.

24.
a)

a) 2 and 3

b)

b) 1 and 4

c)

c) 1 and 3

d)

d) 2 and 4

e)

e) None of the above