You are on page 1of 4

Course: Easy-to-follow Java programming

The quiz questions


Answer the questions below to review what you have learned in Video 6. You will
find the right answers after the questions in the solution section.

1. Put the different parts of a function that returns the bigger number into the
right order.

int first, int second

int

bigger

public static

if (first > second) {


return first;
} else {
return second;
}

Duckademy IT courses – www.duckademy.com


2. Which one of the following code sections will print out 2?
(Multiple selection is allowed.)

public static void change(int[] arr) {


arr[0] = 2;
}

public static void main(String[] args) {


int[] a = {1,2,3};
change(a);
System.out.println(a[0]);
}

public static void change(int element) {


element = 2;
}

public static void main(String[] args) {


int a = 0;
change(a);
System.out.println(a);
}

3. What is the meaning of the Java’s main function header


public static void main(String[] args)?

A function which does not return any value, and has


a parameter of a String

A function which does not return any value, and has


a parameter of a String array

A function which returns an integer value, and has


a parameter of a String array

Duckademy IT courses – www.duckademy.com


----------------------------------------------------------------------------------------------------------------

The answers

1. Put the different parts of a function that returns the bigger number into the
right order.

5 int first, int second

9 }

2 int

6 )

3 bigger

7 {

4 (

1 public static
8 if (first > second) {
return first;
} else {
return second;
}

public static
int
bigger
(
int first, int second
)
{
if (first > second) {
return first;
} else {
return second;
}
}

Duckademy IT courses – www.duckademy.com


2. Which one of the following code sections will print out 2?
(Multiple selection is allowed.)

public static void change(int[] arr) {


arr[0] = 2;
}

public static void main(String[] args) {


X int[] a = {1,2,3};
change(a);
System.out.println(a[0]);
}

public static void change(int element) {


element = 2;
}

public static void main(String[] args) {


int a = 0;
change(a);
System.out.println(a);
}

An array variable is a reference variable, i.e. you store only the location of the array in
the variable.
When you call a function with an array as a parameter, only this reference or location is
copied, the original and the copied reference points to the same array. If you modify one
of the elements of the array inside the function, it modifies the element of the only array...
This only array can be referenced by "arr" inside change() and "a" inside main().

3. What is the meaning of the Java’s main function header


public static void main(String[] args)?

A function which does not return any value, and has


a parameter of a String

A function which does not return any value, and


X
has a parameter of a String array

A function which returns an integer value, and has


a parameter of a String array

Duckademy IT courses – www.duckademy.com

You might also like