1.
In object-oriented programming a class is
Correct Answer
C. 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.
2.
In object-oriented programming a method is
Correct Answer
E. 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.
3.
The return type of a method
Correct Answer
B. 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.
4.
To pass additional data to a method we specify a
Correct Answer
C. 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".
5.
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.
6.
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.
7.
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.
8.
A compiler
Correct Answer
C. 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.
9.
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.
10.
This kind of comment tag is used for what kind of comments?
//
Correct Answer
B. Single line
Explanation
This kind of comment tag is used for single line comments.
11.
_________: - 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.
12.
The ".class file" contains this kind of code.
Correct Answer
byte, byte code, Byte, Byte Code, Byte code
Explanation
The ".class file" contains byte code. Byte code is a low-level representation of a program that is executed by the Java Virtual Machine (JVM). It is generated by the Java compiler from the source code and is platform-independent. The byte code is stored in the .class file, which can then be executed by the JVM. The terms "byte" and "Byte" are also mentioned in the answer, but they are not directly related to the code stored in the .class file.
13.
A class name is written in this format
Correct Answer
UpperCamelCase, uppercamelcase, upper camel case
Explanation
The class name can be written in three different formats: UpperCamelCase, uppercamelcase, and upper camel case. UpperCamelCase is a naming convention where each word in the class name starts with an uppercase letter and there are no spaces between the words. uppercamelcase is similar to UpperCamelCase but starts with a lowercase letter. upper camel case is a format where each word starts with an uppercase letter and there is a space between the words.
14.
A method is written in this format.
Correct Answer
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.
15.
Readable, English like code that is written by a programmer in a particular programming language and is saved in the ".java" file.
Correct Answer
source, Source
Explanation
The given answer is correct because it accurately identifies the two variables that represent the readable code written by a programmer in a specific programming language and saved in a ".java" file. The variables "source" and "Source" are appropriately named to indicate their purpose in storing the code.
16.
_____________ classes have subclasses. Choose the best answer.
Correct Answer
B. Super
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.
17.
How would you call or invoke the following method?
public void move()
{
setLocation(getX() + 5, getY();
}
Correct Answer
C. 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.
18.
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.
19.
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.
20.
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.
21.
This kind of comment tag is used for what kind of comments?
/*
*/
Correct Answer
B. Group
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.
22.
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.
23.
Reasons for using comment tags
Correct Answer(s)
A. Describe your code so other programmers can follow it
B. Help document your code so you can follow it
C. 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.
24.
The general "if statement" format it is
if ( _______________ )
{
statements to execute
}
Correct Answer
B. 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.
25.
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.
26.
You cannot right click on the Animal Class in our Crab world scenario and create an object. What kind of class is the Animal class?
Correct Answer
abstract, Abstract, abstract class
Explanation
The Animal class in our Crab world scenario is an abstract class. This means that it cannot be instantiated directly to create objects. Abstract classes are designed to be inherited by other classes, which can then create objects. In this scenario, the Animal class serves as a base class for other specific animal classes, such as Crab, and provides common functionality and attributes that can be shared among its subclasses.
27.
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.
28.
Calling this kind of method is like a command.
Correct Answer
C. Void
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.
29.
A boolean return data type gives us a true false return.
Correct Answer
A. True
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.
30.
How many parameters does this method have?
compare (int x, int y, int z)
Correct Answer
3
three
Three
Explanation
The method "compare" has three parameters: x, y, and z. The data type for each parameter is "int". The answer is 3, three, or Three.
31.
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.
32.
It is good naming convention to name a class in Greenfoot “crab” .
Correct Answer
B. False
Explanation
Classes should be capitalized.
33.
Single line comment tags are written with ____
Correct Answer
//
two forward slashes
2 forward slashes
Explanation
//- single line comment tags
/** */ - group comment tags
34.
Which are correct ways to indicate 25%
Correct Answer(s)
A. GetRandomNumber(100) < 25
B. GetRandomNumber(4) < 1
C. 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.
35.
Strings are indicated with double quotes.
Correct Answer
B. True
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.
36.
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.
37.
What class is this method from?
static int getRandomNumber(int limit)
Correct Answer
Greenfoot
Explanation
This method, static int getRandomNumber(int limit), belongs to the Greenfoot class.
38.
Write a method call that will return a random integer between 0 and 10.
Correct Answer
C. Greenfoot.getRandomNumber(10);
Explanation
enfoot.getRandomNumber(10); The numbers fall between 0 and 10 so they would include 0, 1, 2, ...9.
39.
Methods that belong to classes (as opposed to objects) are marked with the keyword static in their signature.
Correct Answer
A. True
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.
40.
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.
41.
Write an if statement that tells an object to turn 17 degrees, but only 31 percent of the time.
Correct Answer
B. If (Greenfoot.getRandomNumber(100) <31) turn(17);
Explanation
A semicolon will stop an if condition for executing You need () around the conditional.
42.
This statement tells an object to turn a random number of degrees between -20 and 20.
Greenfoot.getRandomNumber(-20, 20);
Correct Answer
A. True
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.
43.
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
D. 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.
44.
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);
}
Correct Answer
B. False
Explanation
no return type
45.
Common characteristics of a constructor’s signature
Correct Answer(s)
A. Same name as the class
B. No return type
C. 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.
46.
This is a valid constructor
public Elephant()
{
imageDown = new GreenfootImage("elephant.png");
imageUp = new GreenfootImage("elephant2.png");
setImage(imageDown);
}
Correct Answer
A. True
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.
47.
A constructor must be called to create an object
Correct Answer
A. True
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.
48.
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.
49.
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.
50.
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
B. 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.