2.
Methods that are void methods are like commands
Example:
public void move()
Explanation
Void methods in programming are used to perform certain actions or tasks without returning any value. They are like commands because they are executed to carry out a specific action or operation. In the given example, the "move()" method is a void method which suggests that it is used to perform a movement action without returning any result. Therefore, the statement "Methods that are void methods are like commands" is true.
3.
Void means the method does not return anything.
Explanation
The explanation for the given correct answer is that in programming, a void method is a method that does not return any value. When a method is declared as void, it means that it performs certain actions or tasks but does not produce any output or return any value. Instead, it may modify the state of objects or variables within the method. Therefore, the statement "Void means the method does not return anything" is true.
4.
-
Suppose the method to call is defined in the same class or inherited from another class
In general, the format is:
methodName(parameters…)
Explanation
The given correct answer is true. This means that if the method to call is defined in the same class or inherited from another class, the format to call the method is generally "methodName(parameters...)". This indicates that the method can be called using the specified format.
5.
Which is the best example of how to use braces when creating a conditional statement?
Correct Answer
A. If (condition)
{
statement(s);
}
Explanation
You can use no braces when you only have one statement in a conditional. However, it is best practice to always use braces in a conditional statement. If you have multiple statements and no braces, only the first line of the statement will execute.
6.
Common characteristics of a constructor’s signature.
It is the same name as the class
It has no return type
It is preceded by the public visibility modifier
Explanation
A constructor's signature refers to the unique combination of its name and parameters. The first characteristic states that the constructor's signature should have the same name as the class it belongs to. This is because a constructor is used to create an object of the class, and having the same name as the class helps to identify and differentiate it from other methods. The second characteristic mentions that a constructor has no return type, as its purpose is to initialize the object and not to return any value. Lastly, the third characteristic states that a constructor is typically preceded by the public visibility modifier, which allows it to be accessed from outside the class.
7.
A protected modier on a method means that the method
-
may not be accessed directly by any code outside the class (can’t get to it with the ‘.’)
-
is inherited by subclasses
Explanation
A protected modifier on a method means that the method may not be accessed directly by any code outside the class (can't get to it with the '.'). However, it is inherited by subclasses, allowing them to access and use the method.
8.
To debug your code, the following methods are the best to use.
Correct Answer(s)
A. Use the debugger and set breakpoints
A. Use "System.out.println" to output information you would like to check
Explanation
random guessing is generally inefficient and time consuming.
9.
Methods that return a value are like questions.
Example:
public boolean canMove()
Explanation
Methods that return a value are like questions because they allow us to ask the method if a certain condition or action is possible or true. In this specific example, the method "canMove()" is asking if it is possible to move, and it returns a boolean value of true or false depending on the situation. Therefore, the correct answer is true, indicating that it is possible to move.
10.
We know which format to use when declaring a methodName by checking for the static keyword.
Explanation
The statement is true because when declaring a methodName, we can determine the format by checking for the presence of the static keyword. If the static keyword is present, it means that the method belongs to the class itself and can be accessed without creating an instance of the class. If the static keyword is not present, it means that the method belongs to the instances of the class and can only be accessed through an object of the class.
11.
-
Suppose the method is not in the same class or inherited from another class
In general, the format is:
-
ClassName.methodName(parameters…) OR
-
objectName.methodName(parameters…)
Explanation
If the method is not in the same class or inherited from another class, then it is not accessible using the ClassName.methodName() or objectName.methodName() format. Therefore, the statement "Suppose the method is not in the same class or inherited from another class" suggests that the correct answer is True.
12.
-
Why should you use Comments tags? Two primary reasons
Correct Answer(s)
A. To explain code you are writing
A. To check for errors
Explanation
Comments tags are used for two primary reasons. Firstly, they are used to explain the code that you are writing. This helps in providing clarity and understanding to other developers who may be working on the code in the future. Secondly, comments tags are used to check for errors. By adding comments to your code, you can easily identify and fix any mistakes or bugs that may be present. It is important to note that using comments tags does not directly make your code prettier, but it does enhance its readability and maintainability.
13.
Greenfoot.getRandomNumber(8) + 1;
Thid method would return numbers between ____ and 8
Correct Answer(s)
1
Explanation
random numbers between 0 and 8 include 0, 1, 2, ...7.
Adding 1 to any of these numbers means the lowest
number is 1, not zero
14.
“Functions” are represented by Java methods whose returnType is not void.
Explanation
The given statement is true because in Java, functions are represented by methods that have a return type other than void. In Java, a method with a return type is expected to return a value of that type, whereas a method with a void return type does not return any value. Therefore, if a Java method has a return type other than void, it can be considered as a function.
15.
The terminal window appears automatically when the first System.out.println statement is executed.
Explanation
The terminal window appears automatically when the first System.out.println statement is executed because the System.out.println statement is used to print a message to the standard output, which is typically the terminal window. When the program is run, the statement is executed and the message is displayed in the terminal window. Therefore, it is true that the terminal window appears automatically when the first System.out.println statement is executed.
16.
Translate source code into machine code that a computer can understand and execute.
Correct Answer
compile
compiling
compilation
Explanation
The process of translating source code into machine code that a computer can understand and execute is called compilation. This involves converting the high-level programming language used in the source code into low-level instructions that the computer's processor can directly execute. The terms "compile," "compiling," and "compilation" all refer to this process.
17.
SetLocation(100, 150);
The parameters of 100 and 150 tell you that the y coordinate is 100 and the x coordinate is 150.
Explanation
setLocation(int x, int y);
18.
Mark all answers that are correct
Write a method to show 50-50 probability
Correct Answer(s)
A. GetRandomNumber(2) < 1
A. GetRandomNumber(100) < 50
Explanation
The explanation for the given correct answer is that the expression "getRandomNumber(2) < 1" ensures a 50-50 probability because the getRandomNumber(2) method returns a random number between 0 and 1, and checking if it is less than 1 will always be true. Similarly, the expression "getRandomNumber(100) < 50" ensures a 50-50 probability because the getRandomNumber(100) method returns a random number between 0 and 100, and checking if it is less than 50 will be true half of the time.
19.
Complete this for loop that would create 5 different Worms automatically and place them in random locations in the world.
for ( int i = 0 ; i < _______ ; i++)
{
addObject(new Worm(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight());
}
Correct Answer(s)
5
Explanation
The correct answer is 5 because the for loop is set to iterate 5 times. This means that the code inside the loop will be executed 5 times, resulting in the creation of 5 different Worm objects and placing them in random locations in the world.
20.
Greenfoot.getRandomNumber(10);
This method would return numbers from 0 to ____
Correct Answer(s)
9
Explanation
between 0 and 10 does not include 10.
21.
You do not have to use dot notation is a method is in the same class you are writing the method in.
Explanation
In object-oriented programming, dot notation is used to access methods and properties of an object. If a method is in the same class where we are writing another method, we can directly call that method without using dot notation. This is because methods within the same class are accessible without any explicit reference. Therefore, the statement "You do not have to use dot notation if a method is in the same class you are writing the method in" is true.
22.
A __________________is a mechanism used to pass additional data into a method.
Example:
public void move(distance);
Correct Answer
parameter
Parameter
Explanation
In programming, a parameter is a mechanism used to pass additional data into a method. It allows the method to receive input values that can be used within the method's code. In the given example, the "distance" is a parameter that is passed into the "move" method. This parameter can be used within the method to perform calculations or operations related to the distance. The term "Parameter" refers to the concept itself, while "parameter" refers to a specific instance or variable used as a parameter in a particular method.
23.
Comments that describe your code are often concise and begin with action words. Assume the reader of your code already understands the language.
Explanation
The given correct answer is "True" because the statement suggests that comments in code are often concise and begin with action words. This implies that comments should be brief and describe what the code is doing, rather than explaining the language itself.
24.
What is the method name for the following method?
public void eat()
Correct Answer
eat()
eat
Explanation
The method name for the given method is "eat()". In Java, the method name is specified after the access modifier (in this case, "public") and the return type (in this case, "void"). The parentheses after the method name indicate that it is a method and can be called with or without arguments. In this case, the method name is "eat" and it should be called using "eat()".
25.
A class called Ant extends the Actor class.
Correct Answer
A. Actor is the super class to Ant
Explanation
In object-oriented programming, a superclass is a class that is inherited by another class, known as a subclass. In this scenario, the class "Ant" extends the class "Actor", indicating that "Ant" is a subclass of "Actor". Therefore, "Actor" is the superclass to "Ant".
26.
Write a statement that will declare an integer instance variable called count and set its initial value to 0. (2 marks)
Correct Answer
A. Public int count = 0;
Explanation
Variables have a data type and name. You initialize the variable by setting it equal to a value.
27.
Constructors can never have parameters.
Explanation
EX.
public Student(String parFirstName, String parLastName)
{
firstName = parFirstName;
lastName = parLastName;
}
28.
This kind of error will allow your program to compile but will give you information that is wrong.
Correct Answer
logic
logic error
Explanation
A logic error is a mistake in the program's logic that causes it to produce incorrect or unexpected results. It is a type of error that allows the program to compile without any syntax errors, but the output or behavior of the program is not what was intended. In this case, the error is related to logic, specifically a logic error. This means that the program may run without any errors, but the information it provides is incorrect or misleading.
29.
Write an if statement that would play a sound when the “D” key or the “F” key is pressed, AND wormsEaten is between 3 and 6 inclusive.
if (Greenfoot.isKeyDown(“D”) || Greenfoot.isKeyDown(“F”) &&( wormEaten >= 3) && (wormsEaten <=6)))
Correct Answer
A. If (Greenfoot.isKeyDown(“D”) || Greenfoot.isKeyDown(“F”) &&( wormEaten >= 3) && (wormsEaten
Explanation
The correct answer is the first option: if (Greenfoot.isKeyDown("D") || Greenfoot.isKeyDown("F") && (wormEaten >= 3) && (wormsEaten
30.
If a class has subclasses, it is considered to be a _____________ class.
Correct Answer
super
parent
Explanation
super or parent class
31.
You do not have to use dot notation if a method is inherited.
Explanation
When a method is inherited, it means that it is passed down from a parent class to a child class. In this case, the statement is saying that when a method is inherited, we do not have to use dot notation to access or call that method. Instead, we can directly use the method name without any additional notation. Therefore, the correct answer is true.
32.
Constructors do not have the same name as the class.
Explanation
Constructors do have the same name as the class. A constructor is a special method that is automatically called when an object of a class is created. It is used to initialize the object's state. The name of the constructor must match the name of the class. Therefore, the statement "Constructors do not have the same name as the class" is false.
33.
On the following picture "void setDirection(int direction)" is called the ____________________ of the method.
Correct Answer
A. 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"), the return type ("void"), and the parameter it accepts ("int direction"). Therefore, the correct answer is "signature".
34.
What kind of error will keep your program from compiling?
For example, you forget to put a ";" at the end of a variable that you declare.
Correct Answer
syntax
Explanation
A syntax error refers to a mistake in the structure or grammar of a program that prevents it from being compiled. This can occur when there is a missing or misplaced symbol, such as a semicolon, parentheses, or quotation marks. In this case, forgetting to put a semicolon at the end of a variable declaration would result in a syntax error and the program would fail to compile.
35.
Memory that belongs to the object that is used to store information(objects or values) for later use is called an ______________ variable.
Correct Answer
instance
Explanation
In object-oriented programming, an instance variable is a variable that belongs to a specific object. It is used to store information or values that are specific to that object and can be accessed and modified by the methods of that object. Unlike local variables, which have a limited scope and are destroyed once the method execution is completed, instance variables persist as long as the object exists. Therefore, an instance variable is the correct term for memory that belongs to an object and is used to store information for later use.
36.
/*
*/
These tags are for single line code comments
Explanation
The given answer is false because the tags mentioned in the question, "//" and "/* */", are actually used for single and multi-line comments in programming languages like Java, C++, and JavaScript. Single line comments are indicated by "//" and multi-line comments are indicated by "/* */". Therefore, the correct answer is false.
37.
Translate source code into byte code which the Java Interpreter (JVM – Java Virtual Machine) can understand.
Correct Answer
compile
Explanation
The process of translating source code into byte code that can be understood by the Java Interpreter (JVM) is called compilation.
38.
Strings should be put in single quotes
Explanation
Double quotes
39.
-
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)
super( ___ , ___ , ___ );
Correct Answer
200, 300, 5
200 300 5
(200, 300, 5);
super(200, 300, 5);
Explanation
The correct answer is "super(200, 300, 5);" because the "super()" method is used to call the constructor of the superclass, in this case, the World class. By passing in the values 200, 300, and 5 as arguments, we are setting the dimensions of the world to be 200 cells by 300 cells, with each cell being 5 by 5 pixels.
40.
What is the return value of the following method:
private boolean atWorldEdge()
Correct Answer
boolean
Explanation
The return value of the method "atWorldEdge()" is a boolean. This means that the method will either return true or false. The method is likely designed to check if a certain object or entity is at the edge of the world or not. If the object is at the edge, the method will return true, indicating that it is at the world edge. If the object is not at the edge, the method will return false.
41.
Use an ________________ variable when it exhibits a natural “has-a” relationship to the object
Correct Answer
instance
Explanation
When an object has a natural "has-a" relationship with another object, it means that the first object contains or possesses the second object. In this context, using an "instance" variable is appropriate because it signifies that the object has an instance of another object associated with it. The "instance" variable can be used to store and access the related object, allowing for a clear and logical representation of the relationship between the two objects.
42.
What word is used to show that a class inherits methods and properties from a super class.
Correct Answer
extends
Explanation
The word "extends" is used in object-oriented programming to indicate that a class is inheriting methods and properties from a super class. Inheritance allows a class to reuse code from another class, known as the super class. By using the "extends" keyword, the subclass can access and use the methods and properties of the super class, without having to redefine them. This promotes code reusability and helps in creating a hierarchical structure of classes, where subclasses can add or modify functionality as needed.
43.
The method "static int getRandomNumber(int limit)" is from which class?
Correct Answer
Greenfoot
Explanation
The method "static int getRandomNumber(int limit)" is from the Greenfoot class.
44.
Special methods that allow one to instantiate (construct) an object from a class.
Correct Answer
Constructor
Constructors
constructor
constructors
Explanation
The correct answer is "Constructor, Constructors, constructor, constructors". A constructor is a special method in a class that is used to create and initialize objects of that class. It has the same name as the class and is called automatically when an object is created. Constructors can have parameters to initialize the object with specific values. By using constructors, we can instantiate (construct) objects from a class.
45.
To straighten out your code and make it have proper indentations, you can use __________ from the Edit Menu.
Correct Answer
Auto-layout
auto-layout
auto layout
Auto layout
Auto Layout
Explanation
To straighten out your code and make it have proper indentations, you can use the "Auto-layout" feature from the Edit Menu. This feature automatically adjusts the layout and indentation of your code, ensuring that it is properly organized and easy to read. By selecting this option, you can save time and effort in manually adjusting the indentations of your code.
46.
= is used as a Boolean statement to determine if something is true or false
== assigns a value to the variable on the left side of the equals sign.
Explanation
== is used as a Boolean statement to determine if something is true or false
= assigns a value to the variable on the left side of the equals sign.
47.
Attempt to always use( local or instance ) variables except when the variable exhibits a natural “has-a” relationship to the object.
A student has a first name, last name, id, social security number
A car has a make, model, type, color
Correct Answer
local
Explanation
The explanation for the given correct answer is that when designing a class, it is generally recommended to use local variables instead of instance variables, unless the variable has a natural "has-a" relationship to the object. In the given examples, the attributes of a student (first name, last name, id, social security number) and a car (make, model, type, color) are specific to each individual instance of the class. Therefore, it makes sense to use local variables to store these attributes within methods or constructors, rather than storing them as instance variables.
48.
Write the method call for the method signature.
(How would you call the method in your code?)
public void eat( )
Correct Answer
eat();
Explanation
The correct way to call the method is by simply writing "eat();" in your code. This will execute the "eat" method without any arguments.
49.
If (atWorldEdge());
This is the correct way to write the if conditional.
Explanation
It should never have a " ; " at the end of the condition. It stops the statements from executing.