2.
A boolean return data type gives us a true false return.
Explanation
A boolean return data type is used to indicate a logical value of either true or false. It is commonly used in programming languages to represent conditions or comparisons. When a function or expression returns a boolean value, it means that it will only return either true or false. Therefore, the statement "A boolean return data type gives us a true false return" is correct.
3.
Single line comment tags are written with ____
Correct Answer
//
two forward slashes
2 forward slashes
Explanation
//- single line comment tags
/** */ - group comment tags
4.
This kind of comment tag is used for what kind of comments?
//
Correct Answer
A. Single line
Explanation
This kind of comment tag is used for single line comments.
5.
Constructors are sometimes used to initialize instance variables – especially if they represent objects.
Explanation
Example
public class Elephant extends Actor
{
private GreenfootImage imageUp;
private GreenfootImage imageDown;
/**
* Create an elephant and give it two images to animate.
*/
public Elephant()
{
imageDown = new GreenfootImage("elephant.png");
imageUp = new GreenfootImage("elephant2.png");
setImage(imageDown);
}
6.
The code that a programmer writes is called _______________ code.
Correct Answer
source
Explanation
The code that a programmer writes is commonly referred to as source code. It is the human-readable version of a program that is written in a programming language. The terms "source", "source code", "Source", "Source Code", and "Source code" all refer to the same concept.
7.
This kind of comment tag is used for what kind of comments?
/*
*/
Explanation
The given correct answer suggests that the comment tag in question is used for grouping comments together. This implies that the comment tag mentioned is used to create a block of comments or to categorize and organize comments that are related to each other.
8.
It may be accessed directly by any code outside the class
and it is inherited by subclasses.
Explanation
The correct answer is "public" because a public member or method in a class can be accessed directly by any code outside the class. It is also inherited by subclasses, meaning that subclasses can access and use the public member or method.
9.
Attempt to always use local variables except when the variable exhibits a natural “has-a” relationship to the object
For Example:
A car has a make, model, type, color
Explanation
The explanation for the given correct answer is that it is generally recommended to use local variables instead of instance variables, unless the variable has a natural "has-a" relationship with the object. This means that if the variable is not directly related to the object's properties or characteristics, it should be declared as a local variable. This helps in keeping the code more organized and reduces the risk of unintended side effects or conflicts in the code.
10.
How does Step differ from Step into?
Correct Answer
A. Step steps over methods, Step Into steps into methods
Explanation
Step and Step Into are both debugging techniques used in programming. Step is used to execute the current line of code and move to the next line, without stepping into any method calls. It allows the programmer to quickly navigate through the code and skip over method calls if they are not of interest. On the other hand, Step Into is used to execute the current line of code and if there is a method call on that line, it will step into that method and allow the programmer to debug it line by line. This is useful when the programmer wants to understand the inner workings of a specific method.
11.
Methods that belong to classes (as opposed to objects) are marked with the keyword static in their signature.
Explanation
Methods that belong to classes (as opposed to objects) are marked with the keyword static in their signature. This means that these methods can be called directly on the class itself, without the need to create an instance of the class. The keyword "static" indicates that the method is associated with the class itself, rather than with any specific instance of the class. Therefore, the statement "Methods that belong to classes (as opposed to objects) are marked with the keyword static in their signature" is true.
12.
When a method returns nothing this special word is used for the return type:
Correct Answer
void, Void
Explanation
The return type "void" is used when a method does not return any value. It indicates that the method performs a certain task or operation but does not provide any output or result. In programming, when a method has a return type of "void", it means that the method's purpose is to execute a set of instructions without producing a specific value.
13.
To pass additional data to a method we specify a
Correct Answer
A. Parameter
Explanation
When we want to pass additional data to a method, we use a parameter. A parameter is a variable that is defined in the method's signature and is used to receive the data that is passed when the method is called. By specifying a parameter, we can pass values or objects to a method and use them within the method's code. Therefore, the correct answer is "parameter".
14.
_________: - Translate source code into byte code which the Java Interpreter (JVM- Java Virtual Machine) can understand.
Correct Answer
compile
Compile
compilation
compiling
Explanation
The correct answer is "compile". In Java, the process of converting source code into byte code is known as compilation. The byte code is then executed by the Java Virtual Machine (JVM). The other options, "Compile", "compilation", and "compiling", are variations of the correct answer and all refer to the same process of converting source code into byte code.
15.
How would you call or invoke the following method?
public void move()
{
setLocation(getX() + 5, getY();
}
Correct Answer
A. Move();
Explanation
The correct way to call or invoke the method "move()" is by simply writing "move();" without any additional code or characters. This will execute the code inside the method, which in this case moves the object's location by adding 5 to the current X coordinate and keeping the Y coordinate unchanged.
16.
Using a dot between a class name and a method name is called ____ ____.
Correct Answer
dot notation
Dot notation
Dot Notation
Explanation
Using a dot between a class name and a method name is called dot notation. This notation is commonly used in programming languages to access methods and properties of a class or object. It allows for clear and concise code by indicating the relationship between the class and the method being called. The dot serves as a separator and signifies that the method belongs to the class.
17.
A constructor must be called to create an object
Explanation
A constructor is a special method that is automatically called when an object is created. It is responsible for initializing the object's state. Without calling the constructor, the object would not be properly initialized and may not function correctly. Therefore, it is necessary to call the constructor in order to create an object.
18.
In object-oriented programming a method is
Correct Answer
A. Code that allows access to an object's attributes or that carries out some other action for the object.
Explanation
A method in object-oriented programming is a block of code that allows access to an object's attributes or carries out some other action for the object. It is a fundamental concept in object-oriented programming and is used to define the behavior of an object. By defining methods, we can encapsulate functionality within objects and interact with their attributes in a controlled manner. Methods can be used to manipulate data, perform calculations, or execute specific actions based on the object's state. They provide a way to organize and structure code in a modular and reusable manner.
19.
Calling this kind of method is like a command.
Explanation
Calling a method with the "void" return type is like giving a command because it means that the method does not return any value. When we call a method with a void return type, we are essentially asking the program to perform a specific action or task without expecting any result or value in return. This is similar to giving a command or instruction to the program to carry out a particular operation without the need for any feedback or output.
20.
This is a valid constructor
public Elephant()
{
imageDown = new GreenfootImage("elephant.png");
imageUp = new GreenfootImage("elephant2.png");
setImage(imageDown);
}
Explanation
The given constructor is valid because it initializes the instance variables "imageDown" and "imageUp" with new GreenfootImage objects, and then sets the image of the Elephant object to "imageDown". Therefore, the correct answer is true.
21.
It is good naming convention to name a class in Greenfoot “crab” .
Explanation
Classes should be capitalized.
22.
Strings are indicated with double quotes.
Explanation
The given correct answer is "True." This suggests that the statement or condition being evaluated is considered to be true. It indicates that the statement is valid or accurate.
23.
Given the following constructor, what is the correct way to add an elephant object from this constructor at coordinates, 50,50?
public Elephant()
{
imageDown = new GreenfootImage("elephant.png");
imageUp = new GreenfootImage("elephant2.png");
setImage(imageDown);
}
Correct Answer
A. AddObject(new Elephant(), 50,50)
Explanation
The correct way to add an elephant object from this constructor at coordinates 50,50 is by using the addObject() method, passing in a new instance of the Elephant class as the first argument, and the coordinates 50,50 as the second and third arguments. This will add a new Elephant object to the world at the specified coordinates.
24.
You may not be accessed directly by any code outside the class (can’t get to it with the ‘.’)
and is not inherited by subclasses.
Correct Answer
A. Private
Explanation
Private access modifier restricts access to the class members only within the class itself. It cannot be accessed directly by any code outside the class using the dot operator. It is the most restrictive access level and is not inherited by subclasses. Therefore, private members can only be accessed and modified within the class they are declared in.
25.
This kind of error compiles but the data that comes out is wrong. For example, you want your balloons to move up but they go to the right.
Correct Answer
logic
logic error
Explanation
A logic error refers to a mistake in the programming code that does not cause the program to crash or produce an error message, but it still leads to incorrect results. In this case, the code compiles successfully, but the expected behavior of the balloons moving up is not achieved. Instead, they move to the right. This indicates that there is a logic error in the code that is causing the balloons to move in the wrong direction.
26.
The return type of a method
Correct Answer
A. Specifies what a method call will return
Explanation
A method only returns a single type
Parameters specify the tpe of data a method accepts.
Void is one return type. Others include boolean, int, double etc.
27.
Call the turn method from the given method.
public void turn (int angle)
{
setRotation(getRotation() + angle);
}
Correct Answer
A. Turn(45);
Explanation
The correct answer is "turn(45);" because it correctly calls the turn method with an argument of 45, which will rotate an object by 45 degrees. The other options are either missing the parentheses or the argument, or they are not valid Java syntax.
28.
Public void move() - This part of the method is called the ________________________.
{
}
Correct Answer
signature
Signature
Explanation
The given correct answer is "signature" or "Signature". In programming, the term "signature" refers to the unique combination of a method's name and its parameters. It defines the method's interface and allows the compiler to differentiate between different methods with the same name but different parameters. In this case, the method "move()" is being referred to as the signature of the method.
29.
A compiler
Correct Answer
A. Translates source code into executable code
Explanation
A compiler is a software tool that takes source code written in a high-level programming language and translates it into executable code that can be run on a computer. It analyzes the source code, checks for errors, and generates the corresponding executable code, which can be directly executed by the computer's operating system. This process involves various stages such as lexical analysis, syntax analysis, semantic analysis, code generation, and optimization. The compiler does not maintain a collection of programs or directly test a program's logic, but its main purpose is to translate the source code into a form that the computer can understand and execute.
30.
The general "if statement" format it is
if ( _______________ )
{
statements to execute
}
Correct Answer
A. Condition
Explanation
The given correct answer is "condition". In the general "if statement" format, the keyword "if" is followed by a condition inside the parentheses. This condition can be any boolean statement that evaluates to either true or false. If the condition is true, the statements inside the curly braces will be executed. Therefore, "condition" is the correct answer as it represents the specific condition that determines whether the statements inside the if block will be executed or not.
31.
_____________ classes have subclasses. Choose the best answer.
Explanation
The correct answer is "Super" because "Super" is a class in object-oriented programming that can have subclasses. Inheritance is a fundamental concept in object-oriented programming where a subclass can inherit properties and methods from a superclass. Therefore, "Super" is the best answer as it implies that it is a superclass with the potential to have subclasses.
32.
Reasons for using comment tags
Correct Answer(s)
A. Describe your code so other programmers can follow it
A. Help document your code so you can follow it
A. Trouble shoot your code by commenting out sections of code
Explanation
Comment tags are used in code to describe and document it, making it easier for other programmers to understand and follow. By adding comments, the code becomes more readable and the intentions behind certain sections of code are clarified. Comments also serve as a documentation tool for the original programmer, helping them remember the purpose and functionality of different parts of the code. Additionally, comments can be used to troubleshoot code by temporarily disabling or commenting out sections, allowing for easier identification of bugs or errors.
33.
What class is this method from?
static int getRandomNumber(int limit)
Correct Answer(s)
Greenfoot
Explanation
This method, static int getRandomNumber(int limit), belongs to the Greenfoot class.
34.
In object-oriented programming a class is
Correct Answer
A. A model or template from which objects are created
Explanation
In object-oriented programming, a class serves as a model or template from which objects are created. It defines the properties and behaviors that objects of that class will have. Objects created from a class will have the same structure and behavior as defined by the class, but they can have different values for their properties. This allows for code reusability and organization, as similar objects can be created from the same class without having to redefine their properties and behaviors each time.
35.
How would I write a random number that would show numbers from 1 to 8?
Correct Answer
A. Greenfoot.getRandomNumber(8) + 1;
Explanation
The correct answer is "Greenfoot.getRandomNumber(8) + 1;". This is because the method "getRandomNumber(8)" generates a random number between 0 and 7. By adding 1 to the result, the range of the random number becomes 1 to 8, which is what the question is asking for.
36.
Which are correct ways to indicate 25%
Correct Answer(s)
A. GetRandomNumber(100) < 25
A. GetRandomNumber(4) < 1
A. GetRandomNumber(16) < 4
Explanation
The given answer is correct because it correctly indicates three different ways to represent 25%. The first expression "getRandomNumber(100) < 25" means that if a random number between 0 and 99 is generated, it will be less than 25. The second expression "getRandomNumber(4) < 1" means that if a random number between 0 and 3 is generated, it will be less than 1. The third expression "getRandomNumber(16) < 4" means that if a random number between 0 and 15 is generated, it will be less than 4.
37.
Write a method call that will return a random integer between 0 and 10.
Correct Answer
A. Greenfoot.getRandomNumber(10);
Explanation
enfoot.getRandomNumber(10); The numbers fall between 0 and 10 so they would include 0, 1, 2, ...9.
38.
Write an if statement that tells an object to turn 17 degrees, but only 31 percent of the time.
Correct Answer
A. If (Greenfoot.getRandomNumber(100) <31) turn(17);
Explanation
A semicolon will stop an if condition for executing You need () around the conditional.
39.
An instance variable is sometimes called a ________
Correct Answer
field
Explanation
field
They are located near the top of a program, generally above the constructor.
40.
This statement tells an object to turn a random number of degrees between -20 and 20.
Greenfoot.getRandomNumber(-20, 20);
Explanation
The statement Greenfoot.getRandomNumber(-20, 20); generates a random number between -20 and 20. Since the question states that the statement tells an object to turn a random number of degrees between -20 and 20, the correct answer is True.
41.
Changing the flow of control in a program to jump to some pre-written code is known as ___________________ a method.
Correct Answer
invoking
Explanation
In programming, when we change the flow of control in a program to jump to some pre-written code, it is referred to as "invoking" a method. Invoking a method means calling or executing a specific block of code that has been defined elsewhere in the program. This allows us to reuse code and perform specific tasks whenever needed by jumping to the invoked method.
42.
Given an integer variable drivingAge that has already been declared, write a statement that assigns the value 17 to drivingAge . So, after your code is executed, the variable drivingAge, will have the value 17.
Correct Answer
drivingAge = 17;
Explanation
int drivingAge = 17; - This statement redeclares the variable. Try again to only assign 17 to drivingAge.
43.
Common characteristics of a constructor’s signature
Correct Answer(s)
A. Same name as the class
A. No return type
A. Public modifier
Explanation
The given answer correctly states the common characteristics of a constructor's signature. A constructor must have the same name as the class it belongs to, ensuring that it is called when an object of the class is created. It should not have a return type, as its purpose is to initialize the object and not to return any value. Additionally, the constructor should have a public modifier, allowing it to be accessed from anywhere in the program. These characteristics are essential for creating and initializing objects in object-oriented programming.
44.
A method is written in this format.
Correct Answer(s)
lowerCamelCase
lowercamelcase
lower camel case
Explanation
The correct answer is "lowerCamelCase, lowercamelcase, lower camel case". This is because the given format is written in lower camel case, which means that the first letter of the identifier is in lowercase and the first letter of each subsequent concatenated word is capitalized. The three variations of the answer show the different ways in which the words can be concatenated, either with or without spaces.
45.
It may not be accessed directly by any code outside the class (can’t get to it with the ‘.’)
and it is inherited by subclasses.
Correct Answer
A. Protected
Explanation
The protected access modifier allows the member to be accessed within the class itself, as well as by any subclasses that inherit from the class. It cannot be accessed directly by any code outside the class using the dot operator. This means that only the class and its subclasses have access to the protected member.
46.
An example of this kind of error would be missing ( ) on a method.
Correct Answer
syntax, syntax error
Explanation
The given correct answer is "syntax, syntax error". This is because the statement is referring to an example of an error related to syntax, specifically the missing parentheses on a method. A syntax error occurs when the code violates the grammar rules of the programming language, making it unable to be executed properly. In this case, the missing parentheses would lead to a syntax error, as the correct syntax requires the use of parentheses in defining and calling methods.
47.
When an object has an "is a" relationship with another object, that relationship is called ____________
Correct Answer
inheritance, inherit
Explanation
When an object has an "is a" relationship with another object, that relationship is called inheritance. Inheritance allows an object to inherit properties and behaviors from another object, known as the parent or superclass. The object that inherits these properties and behaviors is called the child or subclass. Inheritance promotes code reusability and allows for the creation of more specialized objects by extending the functionality of existing objects.
48.
This is a valid constructor
public void AnimalWorld()
{
// Create a new world with 400x300 cells
// with a cell size of 1x1 pixels.
super(400, 300, 1);
}
Explanation
no return type
49.
What is the formal name for the process of creating an object from a class?
Correct Answer
instantiation, instantiating an object
Explanation
The formal name for the process of creating an object from a class is instantiation. It involves the creation of a specific instance of a class, where the object inherits the properties and behaviors defined by the class. Instantiating an object refers to the same process of creating an instance of a class. Both terms are commonly used in object-oriented programming to describe the creation of objects.