1.
On the following picture "void setDirection(int direction)" is called the ____________________ of the method.
Correct Answer
D. Signature
Explanation
The term "signature" refers to the name and parameters of a method. In this case, "void setDirection(int direction)" is the signature of the method being called. It specifies the name of the method (setDirection) and the type and name of its parameter (int direction).
2.
“Functions” are represented by Java methods whose returnType is not void.
Correct Answer
A. True
Explanation
In Java, functions are represented by methods whose returnType is not void. This means that these methods return a value of a specific data type instead of nothing. The returnType specifies the type of value that the method will return when it is called. Therefore, the correct answer is true.
3.
Void means the method does not return anything.
Correct Answer
A. True
Explanation
The statement is true because in programming, a void method is a method that does not have a return type. It is used to perform a task or action without returning a value. When a method is declared as void, it means that it does not return any data back to the caller. Instead, it simply executes the code within the method and then terminates.
4.
Methods that return a value are like questions.
Correct Answer
A. True
Explanation
Methods that return a value can be compared to questions because they allow us to ask the method for a specific value or information, just like we ask questions to get answers. When we call a method that returns a value, it executes its code and provides us with the result, similar to how a question provides us with an answer. Therefore, the statement "Methods that return a value are like questions" is true.
5.
Methods that are void methods are like commands
Correct Answer
A. True
Explanation
Void methods in programming are functions that do not return any value. They are used to perform certain actions or tasks, similar to giving commands. When a void method is called, it executes the code within it and completes the specified action without returning a result. Therefore, the statement that void methods are like commands is true, as they are used to perform actions rather than returning values.
6.
A class called Ant extends the Actor class.
Correct Answer
B. Actor is the super class to Ant
Explanation
The correct answer is "Actor is the super class to Ant". This means that the class "Ant" inherits from the class "Actor". In object-oriented programming, a superclass is a class from which other classes are derived, while a subclass is a class that inherits properties and methods from a superclass. In this case, "Ant" is the subclass and "Actor" is the superclass. This relationship allows the "Ant" class to inherit and use the properties and methods defined in the "Actor" class.
7.
To translate source code into machine code that a computer can understand and execute is called compiling.
Correct Answer
A. True
Explanation
Compiling is the process of converting source code, written in a high-level programming language, into machine code that can be understood and executed by a computer. This process involves various steps such as lexical analysis, syntax analysis, and code optimization. The resulting compiled code can then be run on the target computer architecture. Therefore, the given statement that translating source code into machine code is called compiling is correct.
8.
What is the method name for the following method?
public void eat()
Correct Answer
C. Eat()
Explanation
The method name for the given method is "eat()". This is determined by the combination of the access modifier "public", the return type "void", and the method name "eat()". The access modifier "public" indicates that the method can be accessed from anywhere. The return type "void" means that the method does not return any value. Finally, the method name itself is "eat()".
9.
What is the return value of the following method?
public void setSize(int sze)
Correct Answer
B. Void
Explanation
The return value of the given method is "void". This means that the method does not return any value. It is a type of method that performs a certain action or task, but does not produce a result that can be used or assigned to a variable. In this case, the method "setSize" takes an integer parameter "sze" and does some action with it, but it does not return any value.
10.
The method below has one parameter.
public void eat( )
Correct Answer
B. False
Explanation
zero
11.
You want the dimensions of the world in your Greenfoot scenario to be 200 cells by 300 cells and each cell will be 5 by 5 pixels. Complete the statement below to accomplish this: (3 marks)
Correct Answer
A. Super(200, 300, 5);
Explanation
The correct answer is "super(200, 300, 5);" because the "super" keyword is used to call the constructor of the superclass, in this case, the World class. The parameters passed in the constructor are the width (200 cells), height (300 cells), and cell size (5 pixels). This statement sets the dimensions of the world in the Greenfoot scenario to be 200 cells by 300 cells, with each cell being 5 by 5 pixels.
12.
Write the method call for the method signature.
(How would you call the method in your code?)
public void eat( )
Correct Answer
A. Eat();
Explanation
The correct answer is "eat();". This is the correct method call for the method signature "public void eat()". The method call consists of the method name "eat" followed by parentheses "()". This syntax is used to invoke or call the method in your code.