2.
The best example for the correct way to name a class is
Correct Answer
A. BankAccount
Explanation
The correct way to name a class is "BankAccount" because it follows the standard naming conventions for class names in most programming languages. The convention is to use camel case, where the first letter of each word is capitalized and there are no spaces or underscores between words. This naming convention improves readability and makes the code easier to understand for other developers.
3.
Check all places that you can get information to create methods in Greenfoot
Correct Answer(s)
A. Greenfoot help menu
A. Java documentation
A. Greenfoot documentation
A. Greenfoot web site
Explanation
The Greenfoot help menu, Java documentation, Greenfoot documentation, and Greenfoot website are all sources of information where one can find guidance on creating methods in Greenfoot. These resources provide documentation, tutorials, and examples that can assist in understanding and implementing methods effectively within the Greenfoot environment.
4.
-
Suppose the method to call is defined in the same class or inherited from another class
In general, the format is:
methodName(parameters…)
Correct Answer
A. True
Explanation
The given statement is true because when a method is defined in the same class or inherited from another class, it can be called using the format "methodName(parameters...)" within the same class or any subclass. This allows for the execution of the method and the utilization of its functionality.
5.
SetLocation(100, 150);
The parameters of 100 and 150 tell you that the y coordinate is 100 and the x coordinate is 150.
Correct Answer
A. False
Explanation
setLocation(int x, int y);
6.
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…)
Correct Answer
A. True
Explanation
If the method is not in the same class or inherited from another class, the format to call the method is either ClassName.methodName(parameters) or objectName.methodName(parameters). This means that if the method is not in the same class or inherited, we cannot call the method directly without specifying the class name or object name. Therefore, the answer "True" is correct.
7.
How do we know which format to use when declaring a methodName?
Check for the static keyword.
Correct Answer
A. True
Explanation
When declaring a methodName, we can determine which format to use by checking for the static keyword. The static keyword is used to define a method that belongs to the class itself rather than an instance of the class. If the method is declared with the static keyword, it can be called directly on the class without creating an instance of the class. Therefore, checking for the static keyword can help us determine the format to use when declaring a methodName.
8.
-
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
Using comment tags in code serves two primary purposes. Firstly, it allows you to explain the code you are writing, making it easier for other developers (or even yourself in the future) to understand the purpose and functionality of the code. This can greatly enhance the maintainability and readability of the codebase. Secondly, comments can be used to check for errors by temporarily disabling or commenting out certain sections of code. This can be useful when troubleshooting or debugging, as it helps isolate potential issues and narrow down the source of errors.
9.
/*
*/
These tags are for single line code comments
Correct Answer
A. False
Explanation
The given statement is false because the tags mentioned are not for single line code comments. In HTML, single line code comments are denoted by . The given tags are not recognized as comments in HTML.
10.
Comments that describe your code are often concise and begin with action words. Assume the reader of your code already understands the language.
Correct Answer
A. True
Explanation
The given correct answer is "True". This means that the statement or question being referred to is true or correct.
11.
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.
12.
The terminal window appears automatically when the first System.out.println statement is executed.
Correct Answer
A. True
Explanation
When the first System.out.println statement is executed, it prints the output to the console. As a result, the terminal window, which is the console where the output is displayed, appears automatically. Therefore, the statement "The terminal window appears automatically when the first System.out.println statement is executed" is true.
13.
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.
14.
If (atWorldEdge());
This is the correct way to write the if conditional.
Correct Answer
A. False
Explanation
It should never have a " ; " at the end of the condition. It stops the statements from executing.
15.
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.
16.
What word is used to show that an 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 subclass to inherit and reuse the code from its parent class, promoting code reusability and reducing redundancy. By using the "extends" keyword, the subclass can access and utilize all the public and protected members of the super class, providing a way to create more specialized classes based on existing ones.
17.
What is the return value of the following method:
private boolean atWorldEdge()
Correct Answer
A. Boolean
Explanation
The return value of the method atWorldEdge() is a boolean. This means that the method will either return true or false.
18.
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
A. Syntax
Explanation
Syntax errors occur when the code violates the rules of the programming language. These errors prevent the program from being compiled because the compiler cannot understand the code due to the syntax violation. Forgetting to put a semicolon at the end of a variable declaration is an example of a syntax error. Other examples include misspelling keywords, using incorrect punctuation, or not closing brackets properly.
19.
This kind of error will allow your program to compile but will give you information that is wrong.
Correct Answer
A. Logic
Explanation
This kind of error refers to a logical error in programming. It means that the program will compile without any syntax errors, but the resulting output or information provided by the program will be incorrect. This type of error occurs when there is a mistake in the program's algorithm or logic, causing it to produce incorrect results.