wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Programming Quiz

Total questions: 20

Worksheet time: 13mins

Name
Class
Date
1.

What is the default package in Java?

a)

java.default

b)

java.package

c)

The unnamed package

d)

java.lang

2.

What is the default value of a boolean variable in Java?

a)

True

b)

False

c)

0

d)

Null

3.

What will be the output of the following Java code? { int g = 3; System.out.println(++g * 8); }

a)

24

b)

32

c)

25

d)

33

4.

Which keyword is used to declare a constant variable in Java?

a)

Const

b)

Final

c)

Static

d)

None

5.

In Java, System.out.println(11/4); output is

a)

2.5

b)

2

c)

2.0

d)

3

6.

What is the correct syntax to read input from the user?

a)

Scanner sc = new Scanner(System.in);

b)

System.read();

c)

input sc = new Scanner();

d)

None

7.

System.out.println("Hello\nWorld"); what will be the Output:_____________

a)

Hello\nWorld

b)

HelloWorld

c)

Hello World

d)

Compilation error

8.

Return type _________ indicates that a method will not return a value.

a)

Int

b)

Void

c)

Float

d)

None

9.

Which of the following is a method having same name as that of it’s class?

a)

Object

b)

Class

c)

Constructor

d)

Void

10.

int x = 5; System.out.println(++x + ++x);

a)

11

b)

12

c)

13

d)

None

11.

Which keyword refers to the current object?

a)

Super

b)

Object

c)

This

d)

None

12.

The keyword used to prevent inheritance of a class is:

a)

Abstract

b)

Final

c)

Static

d)

Const

13.

________________allows the same method name but different parameters?

a)

Overriding

b)

Encapsulation

c)

Abstraction

d)

Overloading

14.

Find the output of the following code. int Integer = 24; char String = ‘I’; System.out.print(Integer); System.out.print(String);

a)

Throws Exception

b)

Compile Error

c)

Id

d)

24 I

15.

int a = 10, b = 20; System.out.println(a > b ? a : b);

a)

10

b)

20

c)

30

d)

None

16.

The output of the Java compiler is known as (a)   .

17.

The process of converting one data type into another is called (a)   .

18.

A class is a blueprint for creating (a)   .

19.

The process of binding variables and methods is called (a)   .

20.

class Test { protected float x, y; } class Demo { public static void main(String args[]) { Test t = new Test(); System.out.println(t.x + " " + t.y); } } Output: ____________________________________________________

4 lines