Your browser has JavaScript turned off. This page is best viewed with Javascript enabled. Certain functions on this site will not work, and some style sheets will not load. Check your browser preferences to enable JavaScript.

Teach Yourself Java

Lesson 6 Quiz

1. What is a function in terms of Computer Science?
A group of code lines that performs a specific task
A group of code lines that performs a whole program
Something that contains an ‘init’
The purpose of Java

2. What is the difference between private and public functions?
Public functions are free, you have to buy private ones
Public functions are the only ones you can download
Public functions can be used by anyone, private can only be used by other code in the class you are writing
Public functions can’t be used

3. What are the four parts of a function definition in order?
Public or private, function name, void or returning a value, parameters (if they are applicable)
Function name, void or returning a value, public or private, parameters
Parameters, public or private, void or returning a value, function name
Public or private, void or returning a value, function name, parameters

4. What does num equal after the following code?

public void ChangeNum(int x)
{
    x = x * 4;
    x = x + 3;
}

int num = ChangeNum(4);
3
4
19
None of the above

5. What does word equal after the following code?

public String ChangeText(String wordToChange)
{
    wordToChange = wordToChange + "s";
    return (wordToChange);
}

String newWord = "apple";
String word = ChangeText(newWord);
apple
apples
sapple
None of the above

6. When passing parameters to a function, you MUST do what?
Pass variables by their exact same name that they are listed as in the function definition
Pass variables of the exact same type that are listed in the function definition
Write the value of the variables in the parentheses
Write the type of variable in the parentheses