wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 7: IPS_Ch 06

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Which keyword is used in Java to define a method that does not return any value?

a)

int

b)

void

c)

return

d)

static

2.

What is the term for breaking a program into smaller, reusable pieces in Java?

a)

Compilation

b)

Modularity

c)

Inheritance

d)

Polymorphism

3.

Which of the following is the correct way to declare a method named `calculateSum` that takes two integers and returns their sum?

a)

int calculateSum(int a, int b) { return a + b; }

b)

void calculateSum(int a, int b) { return a + b; }

c)

int calculateSum() { return a + b; }

d)

int calculateSum(int a, int b) { a + b; }

4.

Which of the following best describes the purpose of using methods in Java?

a)

To increase the size of the code

b)

To organize code into reusable blocks

c)

To make code run faster

d)

To avoid using variables

5.

Given the following method signature, what is the return type? ```java public double getArea(double radius) ```

a)

int

b)

double

c)

void

d)

String

6.

Suppose you have a method `public int multiply(int x, int y)`. How would you call this method from another method in the same class to multiply 3 and 4?

a)

multiply(3, 4);

b)

int result = multiply(3, 4);

c)

int multiply = multiply(3, 4);

d)

multiply = multiply(3, 4);

7.

If you want to make a method accessible only within its own class, which access modifier should you use?

a)

public

b)

private

c)

protected

d)

static

8.

Consider the following code snippet: ```java public static int square(int n) { return n * n; } ``` Which of the following statements correctly uses this method to print the square of 5?

a)

System.out.println(square(5));

b)

System.out.println(square());

c)

System.out.println(square(5, 5));

d)

System.out.println(square);

9.

You are designing a Java program to calculate the average of three numbers. Which approach best demonstrates modularity?

a)

Write all code in the main method.

b)

Create a separate method to calculate the average and call it from the main method.

c)

Use global variables for all calculations.

d)

Avoid using any methods.

10.

You are tasked with refactoring a large Java program that contains repeated code for calculating the area of different shapes. How would you use modularity and methods to improve the program’s design?

a)

Copy and paste the calculation code wherever needed.

b)

Create separate methods for each shape’s area calculation and call them as needed.

c)

Write all calculations in a single method regardless of shape.

d)

Avoid using methods and write calculations directly in the main method.