wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Programming Quiz 1

Total questions: 25

Worksheet time: 25mins

Name
Class
Date
1.

Which of the following is not a feature of Java?

a)

Platform independence

b)

Multiple inheritance through classes

c)

Automatic garbage collection

d)

Security features

2.

Java uses which character to terminate statements?

a)

.

b)

:

c)

;

d)

#

3.

What will this output? System.out.println("Hello " + 1 + 2);

a)

Hello 3

b)

Hello 12

c)

Hello 1 2

d)

Compilation Error

4.

Which keyword is used to define a constant value in Java?

a)

static

b)

final

c)

const

d)

constant

5.

Java bytecode is interpreted by:

a)

JVM

b)

JRE

c)

JDK

d)

JavaScript

6.

Best data type for Unicode character?

a)

int

b)

char

c)

byte

d)

String

7.

Output of this code? int[] arr = new int[3]; System.out.println(arr[0]);

a)

Compilation Error

b)

0

c)

null

d)

Garbage value

8.

Which is not a valid variable name?

a)

totalValue

b)

_value

c)

1value

d)

value_1

9.

Widening conversion example?

a)

int to byte

b)

long to int

c)

int to long

d)

float to short

10.

What does this produce? String s = null; System.out.println(s.length());

a)

0

b)

null

c)

Compilation Error

d)

NullPointerException

11.

Result of: 5 + 2 * 3?

a)

21

b)

11

c)

15

d)

10

12.

Output of loop? for (int i = 0; i < 3; i++) { if (i == 1) continue; System.out.print(i); }

a)

012

b)

02

c)

01

d)

123

13.

Logical AND operator in Java?

a)

&

b)

&&

c)

|

d)

||

14.

Ternary operator is used to:

a)

Require only two operands

b)

Return a Boolean result

c)

Replace simple if-else

d)

Throw exception if false

15.

Statement that exits a loop?

a)

break

b)

continue

c)

exit

d)

return

16.

True statement about constructors:

a)

Constructors can return values

b)

Constructors are inherited

c)

Name must match class name

d)

Constructors can be static

17.

What's the output of this code? class Test { Test(int x) { System.out.println("Constructor: " + x); } } Test t = new Test();

a)

Constructor: 0

b)

Compilation Error

c)

Runtime Error

d)

No Output

18.

Method overloading depends on:

a)

Method name and access modifier

b)

Return type only

c)

Number and type of parameters

d)

None of the above

19.

Keyword for class-level members?

a)

fixed

b)

static

c)

final

d)

constant

20.

Which keyword is used to create objects?

a)

new

b)

super

c)

static

d)

class

21.

Output of the following code? class A { void show() { System.out.println("A"); } } class B extends A { void show() { System.out.println("B"); } } A obj = new B(); obj.show();

a)

A

b)

B

c)

Compilation Error

d)

Runtime Error

22.

Keyword to invoke superclass constructor?

a)

super()

b)

this()

c)

base()

d)

init()

23.

Not true about abstract class:

a)

Can have constructors

b)

Can contain concrete methods

c)

Can be instantiated

d)

Can contain static methods

24.

Output of inner class usage? class Outer { class Inner { void display() { System.out.println("Inner"); } } } Outer o = new Outer(); Outer.Inner i = o.new Inner(); i.display();

a)

Compilation Error

b)

Inner

c)

Outer

d)

Runtime Error

25.

Java supports single inheritance through:

a)

Interfaces

b)

Abstract classes

c)

Superclass

d)

Class hierarchy