Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz

Total questions: 46

Worksheet time: 23mins

Name
Class
Date
1.

Java is case-sensitive. Choose the correct statement.

a)

Java treats 'A' and 'a' as the same.

b)

Java treats 'A' and 'a' as different.

2.

In Java, class names should start with an uppercase letter. Pick the correct option.

a)

uppercase letter

b)

lowercase letter

c)

any symbol

3.

In Java, method names should start with a lowercase letter. Which choice is correct?

a)

lowercase letter

b)

uppercase letter

c)

a number

4.

When a class is public, the filename must match the class name. Select the correct statement.

a)

The filename can be any name.

b)

The filename must match the public class name.

c)

The filename must be in all lowercase.

5.

Every Java statement must end with a semicolon. Choose the correct punctuation that should appear at the end.

a)

comma ,

b)

semicolon ;

c)

colon :

6.

How many primitive data types does Java have?

a)

six

b)

seven

c)

eight

d)

nine

7.

Choose the Java primitive type that stores true or false values.

a)

int

b)

boolean

c)

char

d)

double

8.

Choose the Java primitive type that stores a single Unicode character.

a)

char

b)

boolean

c)

long

d)

float

9.

Which pair lists Java floating-point types?

a)

int and short

b)

float and double

c)

byte and long

d)

char and boolean

10.

In the PrimitiveTypes example, variables are declared with a type followed by a name. Select the declaration that matches this pattern.

a)

byte myByte = 127;

b)

127 = byte myByte;

c)

myByte byte = 127;

11.

Variables are containers for storing data values. Choose the statement that matches this idea.

a)

Variables are pictures in a program.

b)

Variables hold data values like numbers or text.

c)

Variables are only for printing messages.

12.

Select the Java syntax pattern for declaring a variable before using it.

a)

value = type name;

b)

type variableName = value;

c)

name = value type;

13.

Which keyword is used in Java to declare a constant whose value cannot change?

a)

static

b)

final

c)

class

d)

return

14.

Which category includes operators like +, -, *, /, %?

a)

Arithmetic Operators

b)

Relational Operators

c)

Logical Operators

d)

Bitwise Operators

15.

Which category includes operators like ==, !=, >, <, >=, <=?

a)

Assignment Operators

b)

Relational Operators

c)

Increment and Decrement Operators

d)

Logical Operators

16.

Which category includes operators like &&, ||, ! ?

a)

Logical Operators

b)

Bitwise Operators

c)

Arithmetic Operators

d)

Assignment Operators

17.

Which category includes operators like ++ and -- ?

a)

Increment and Decrement Operators

b)

Arithmetic Operators

c)

Relational Operators

d)

Bitwise Operators

18.

Which category includes operators like =, +=, -=, *=, /=, %= ?

a)

Assignment Operators

b)

Logical Operators

c)

Arithmetic Operators

d)

Relational Operators

19.

Which category includes operators like ?

a)

Bitwise Operators

b)

Logical Operators

c)

Arithmetic Operators

d)

Relational Operators

20.

In the OperatorsExample code, a and b are integers. Choose the expression that prints their sum.

a)

System.out.println("a + b = " + (a + b));

b)

System.out.println("a - b = " + (a - b));

c)

System.out.println("a * b = " + (a * b));

21.

Basic Calculator: Create a program that takes two numbers and an operator (+, -, *, /) as input, and performs the corresponding operation. What should the program take as input?

a)

Two numbers and one operator

b)

Two operators only

c)

One number only

d)

A temperature and its scale

22.

Temperature Converter: Write a program that converts temperatures between Celsius and Fahrenheit. The program should ask the user for the source scale (C or F), then the temperature, and output the converted temperature. What is the first thing the program should ask the user?

a)

The source scale (C or F)

b)

The destination city

c)

The interest rate

d)

The number of operators

23.

Simple Interest Calculator: Develop a program that calculates simple interest. It should take the principal amount, rate of interest (in percentage), and period (in years) as input, and output the interest amount. Which set of inputs should the program collect?

a)

Principal amount, rate of interest, and period in years

b)

Temperature and source scale

c)

Two numbers and an operator

d)

Username and password

24.

Array Reversal: Which array is the reverse of [2, 4, 6]?

a)

[6, 4, 2]

b)

[2, 6, 4]

c)

[4, 2, 6]

d)

[2, 4, 6]

25.

Unique Elements: After removing duplicate strings from ["apple", "banana", "apple", "banana"], which list shows only unique items?

a)

["apple", "banana"]

b)

["apple", "banana", "apple"]

c)

["banana"]

d)

["apple", "banana", "banana"]

26.

Word Frequency Counter: A text file says "cat dog cat bird cat." Which word appears most often?

a)

cat

b)

dog

c)

bird

d)

fish

27.

Generic Stack: In a stack, which operation removes the top item?

a)

push

b)

pop

c)

peek

d)

add

28.

Custom Iterator: For a circular buffer, what should the iterator do when it reaches the end?

a)

Stop and return nothing more

b)

Wrap around to the beginning

c)

Delete the buffer

d)

Jump to the middle

29.

ArrayList exercise: Which step creates an ArrayList of strings named URColleges?

a)

Create an ArrayList of strings and call it URColleges.

b)

Store in the created list all the colleges of the University of Rwanda.

c)

Display all the colleges in the list.

d)

Remove any one of the colleges.

30.

ArrayList exercise: Which step adds the colleges of the University of Rwanda to the URColleges list?

a)

Store in the created list all the colleges of the University of Rwanda.

b)

Create an ArrayList of strings and call it URColleges.

c)

Display all the colleges in the list.

d)

Remove any one of the colleges.

31.

ArrayList exercise: Which step shows every college currently in the URColleges list?

a)

Display all the colleges in the list.

b)

Remove any one of the colleges.

c)

Create an ArrayList of strings and call it URColleges.

d)

Display the number of remaining colleges.

32.

ArrayList exercise: Which step takes one college out of the URColleges list?

a)

Remove any one of the colleges.

b)

Display all the colleges in the list.

c)

Store in the created list all the colleges of the University of Rwanda.

d)

Display the number of remaining colleges.

33.

ArrayList exercise: Which step shows how many colleges remain in the URColleges list after changes?

a)

Display the number of remaining colleges.

b)

Create an ArrayList of strings and call it URColleges.

c)

Remove any one of the colleges.

d)

Store in the created list all the colleges of the University of Rwanda.

34.

HashMap exercise: Which step creates a HashMap object named carDetails to store car information?

a)

Create a HashMap object named carDetails that should store the details of a car.

b)

Add the name of the owner of the car to the carDetails object.

c)

Add the year of manufacturing of the car.

d)

Remove the year of manufacturing that you stored.

35.

HashMap exercise: Which step adds the car owner's name into carDetails?

a)

Add the name of the owner of the car to the carDetails object.

b)

Create a HashMap object named carDetails that should store the details of a car.

c)

Add the year of manufacturing of the car.

d)

Remove the year of manufacturing that you stored.

36.

HashMap exercise: Which step stores the car's manufacturing year in carDetails?

a)

Add the year of manufacturing of the car (any year of your choice).

b)

Add the name of the owner of the car to the carDetails object.

c)

Create a HashMap object named carDetails that should store the details of a car.

d)

Remove the year of manufacturing that you stored.

37.

HashMap exercise: Which step gets the owner name from carDetails and saves it in a String variable named carOwner?

a)

Get the name of the owner that you stored and store it in the String variable carOwner.

b)

Create a HashMap object named carDetails that should store the details of a car.

c)

Add the year of manufacturing of the car.

d)

Remove the year of manufacturing that you stored.

38.

HashMap exercise: Which step deletes the manufacturing year from carDetails?

a)

Remove the year of manufacturing that you stored.

b)

Add the year of manufacturing of the car.

c)

Add the name of the owner of the car to the carDetails object.

d)

Create a HashMap object named carDetails that should store the details of a car.

39.

Look at the code. What is the abstract base class name?

a)

Shape

b)

Circle

c)

Rectangle

d)

Resizable

40.

In the Circle class shown, which method is overridden?

a)

getPerimeter

b)

getArea

c)

displayInfo

d)

resize

41.

According to the Circle class code, which formula is used to return the perimeter of a circle?

a)

radius + radius

b)

2 * Math.PI * radius

c)

Math.PI * radius * radius

d)

width + height

42.

In the Rectangle class code, which expression is used to compute area?

a)

width + height

b)

width * height

c)

2 * (width + height)

d)

Math.PI * radius * radius

43.

What kind of type is Resizable in the code?

a)

A class

b)

An interface

c)

An enum

d)

A package

44.

According to the Square class header, what does Square extend?

a)

Shape

b)

Rectangle

c)

Circle

d)

Main

45.

In the Main class code, which object is resized with factor 1.5?

a)

circle

b)

rectangle

c)

square

d)

shape

46.

Which concept from the list is shown by Circle and Rectangle extending Shape?

a)

Polymorphism

b)

Inheritance

c)

Interfaces

d)

Method overriding