Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Programming Quiz

Total questions: 60

Worksheet time: 30mins

Name
Class
Date
1.

What is the core principle of Java programming?

a)

Declarative Programming

b)

Procedural Programming

c)

Object Oriented Programming

d)

Functional Programming

2.

Who developed Java?

a)

Dennis Ritchie

b)

James Gosling

c)

Guido van Rossum

d)

Bjarne Stroustrup

3.

What was Java initially called?

a)

C#

b)

C++

c)

Oak

d)

JavaScript

4.

What is the most important feature of Java?

a)

Memory Management

b)

Multi-threading

c)

Platform-Independent

d)

Platform-Dependent

5.

What does OOP stand for?

a)

Object Oriented Process

b)

Object Oriented Protocol

c)

Object Operated Programming

d)

Object Oriented Programming

6.

Which of the following is NOT a principle of OOP?

a)

Inheritance

b)

Encapsulation

c)

Compilation

d)

Polymorphism

7.

What is encapsulation in Java?

a)

Overriding methods

b)

Creating interfaces

c)

Inheriting properties

d)

Hiding data and methods

8.

What is a class in Java?

a)

A blueprint for objects

b)

A type of variable

c)

A method of execution

d)

A data structure

9.

What is an object in Java?

a)

A blueprint

b)

A method

c)

An instance of a class

d)

A variable

10.

Which of the following is a feature of Java?

a)

Manual Memory Management

b)

Automatic Garbage Collection

c)

Complex Syntax

d)

Static Typing

11.

What is the purpose of the 'new' operator in Java?

a)

To define a method

b)

To declare a variable

c)

To create an object

d)

To create a class

12.

What does JVM stand for?

a)

Java Version Manager

b)

Java Variable Manager

c)

Java Virtual Machine

d)

Java Visual Machine

13.

What is the size of the 'int' data type in Java?

a)

32 bits

b)

16 bits

c)

8 bits

d)

64 bits

14.

Which of the following is a primitive data type in Java?

a)

Array

b)

String

c)

Boolean

d)

Class

15.

What is the range of the 'char' data type in Java?

a)

0 to 65535

b)

0 to 32767

c)

0 to 1023

d)

0 to 255

16.

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

a)

true

b)

false

c)

0

d)

1

17.

Which of the following is used to handle exceptions in Java?

a)

for loop

b)

try-catch block

c)

if-else statement

d)

switch statement

18.

What is the purpose of the 'break' statement in Java?

a)

To declare a variable

b)

To define a method

c)

To continue to the next iteration

d)

To exit a loop

19.

What is the output of the following code: System.out.println(5 + 5);?

a)

Error

b)

50

c)

55

d)

10

20.

Which of the following is a valid identifier in Java?

a)

1stVariable

b)

first variable

c)

first-variable

d)

firstVariable

21.

What is the purpose of the 'return' statement in a method?

a)

To exit the method

b)

To return a value

c)

To declare a variable

d)

To create a loop

22.

What is the correct way to declare an array in Java?

a)

int arr[];

b)

int[] arr;

c)

None of the above

d)

Both A and B

23.

What is a multi-dimensional array in Java?

a)

An array with no elements

b)

An array of arrays

c)

An array with multiple data types

d)

A single array

24.

What is the output of the following code: System.out.println(10 / 3);?

a)

3

b)

3.0

c)

Error

d)

3.33

25.

Which of the following keywords is used to create a class in Java?

a)

define

b)

object

c)

create

d)

class

26.

What is the purpose of the 'this' keyword in Java?

a)

To define a method

b)

To refer to the current object

c)

To declare a variable

d)

To create a new object

27.

What is the output of the following code: System.out.println('A' + 1);?

a)

66

b)

A1

c)

Error

d)

65

28.

Which of the following is NOT a valid loop in Java?

a)

for loop

b)

while loop

c)

repeat-until loop

d)

do-while loop

29.

What is the purpose of the 'continue' statement in a loop?

a)

To exit the loop

b)

To skip the current iteration

c)

To start a new loop

d)

To declare a variable

30.

What is the correct syntax for a switch statement?

a)

switch(expression) { case: }

b)

switch(expression) { case: break; }

c)

switch { case: }

d)

switch(expression) case:

31.

What is the output of the following code: System.out.println(5 == 5);?

a)

Error

b)

false

c)

true

d)

5

32.

Which of the following is a valid way to create a string in Java?

a)

String str = "Hello';

b)

String str = "Hello";

c)

String str = 'Hello';

d)

String str = Hello;

33.

What is the purpose of the 'static' keyword in Java?

a)

To create a class variable

b)

To create a static variable

c)

All of the above

d)

To create a method that belongs to the class

34.

What is the output of the following code: System.out.println(10 % 3);?

a)

Error

b)

3

c)

1

d)

0

35.

Which of the following is a valid way to declare a method in Java?

a)

methodName() void {}

b)

void methodName() {}

c)

void methodName()

d)

methodName() {}

36.

What is the purpose of the 'final' keyword in Java?

a)

To declare a method

b)

To declare a class

c)

To declare a variable

d)

To declare a constant

37.

What is the output of the following code: System.out.println(5 + 5 + '5');?

a)

55

b)

10

c)

Error

d)

15

38.

Which of the following is NOT a feature of Java?

a)

Robust

b)

Low-level programming

c)

Object Oriented

d)

Platform Independence

39.

What is the purpose of the 'abstract' keyword in Java?

a)

To declare a variable

b)

To declare a method without a body

c)

To declare a class that cannot be instantiated

d)

Both A and B

40.

What is the output of the following code: System.out.println(3 + 4 + 5);?

a)

12

b)

Error

c)

7

d)

34

41.

Which of the following is a valid way to create an object in Java?

a)

ClassName obj = ClassName;

b)

ClassName obj = new ClassName();

c)

ClassName obj = ClassName();

d)

ClassName obj = new ClassName;

42.

What is the output of the following code: System.out.println(10 - 3);?

a)

Error

b)

3

c)

10

d)

7

43.

Which of the following is a valid way to handle exceptions in Java?

a)

try-catch block

b)

for loop

c)

if-else statement

d)

switch statement

44.

What is the output of the following code: System.out.println(5 * 5);?

a)

25

b)

Error

c)

10

d)

55

45.

Which of the following is a valid way to declare a boolean variable?

a)

boolean flag = True;

b)

boolean flag = true;

c)

boolean flag = 1;

d)

boolean flag = 'true';

46.

What is the output of the following code: System.out.println(5 > 3);?

a)

false

b)

Error

c)

true

d)

5

47.

Which of the following is a valid way to declare a character variable?

a)

char c = 'A';

b)

char c = A;

c)

char c = "A";

d)

char c = 'A';

48.

What is the output of the following code: System.out.println(5 == 5);?

a)

true

b)

false

c)

5

d)

Error

49.

Which of the following is a valid way to declare a float variable?

a)

float f = 5;

b)

float f = '5.0';

c)

float f = 5.0f;

d)

float f = 5.0;

50.

What is the output of the following code: System.out.println(5 + 5 + 5);?

a)

Error

b)

5

c)

10

d)

15

51.

Which of the following is a valid way to declare a double variable?

a)

double d = 5.0;

b)

double d = 5;

c)

double d = 5.0d;

d)

double d = '5.0';

52.

What is the output of the following code: System.out.println(5 / 2);?

a)

2

b)

2.5

c)

Error

d)

5

53.

Which of the following is a valid way to declare a long variable?

a)

long l = '5';

b)

long l = 5.0;

c)

long l = 5L;

d)

long l = 5;

54.

What is the output of the following code: System.out.println(5 - 3);?

a)

3

b)

Error

c)

2

d)

5

55.

Which of the following is a valid way to declare a short variable?

a)

short s = 5.0;

b)

short s = 5;

c)

short s = 5S;

d)

short s = '5';

56.

What is the output of the following code: System.out.println(5 * 2);?

a)

2

b)

5

c)

Error

d)

10

57.

Which of the following is a valid way to declare a byte variable?

a)

byte b = 5.0;

b)

byte b = '5';

c)

byte b = 5B;

d)

byte b = 5;

58.

What is the output of the following code: System.out.println(5 % 2);?

a)

5

b)

Error

c)

2

d)

1

59.

Which of the following is a valid way to declare a variable in Java?

a)

int a = 5.0;

b)

int a = 5;

c)

int a = '5';

d)

int a = 5L;

60.

What is the output of the following code: System.out.println(5 + 5);?

a)

Error

b)

5

c)

55

d)

10