Greenfoot Ch 1- 4

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Tcarteronw
T
Tcarteronw
Community Contributor
Quizzes Created: 38 | Total Attempts: 32,005
| Attempts: 1,174 | Questions: 64
Please wait...
Question 1 / 64
0 %
0/100
Score 0/100
1. Check all places that you can get information to create methods in Greenfoot

Explanation

The Greenfoot help menu, Java documentation, Greenfoot documentation, and Greenfoot website are all sources where you can get information to create methods in Greenfoot. These resources provide guidance and documentation on the various features and functionalities of Greenfoot, including how to create and use methods in your code. By referring to these sources, you can learn about the syntax, parameters, and usage of different methods, enabling you to effectively create and implement them in your Greenfoot projects.

Submit
Please wait...
About This Quiz
Greenfoot Ch 1- 4 - Quiz

This quiz titled 'Greenfoot Ch 1-4' assesses foundational concepts in Java programming within the Greenfoot environment. It covers IDE usage, method signatures, constructors, compiling, and object-oriented principles such... see moreas inheritance, crucial for beginners in computer science. see less

2. Match the following relational operators.

Explanation

== Equal to
!= Not equal to
> Greater than
= Greater than or equal to

Submit
3. Match the following words with their corresponding definitions.
Submit
4. Match the following:
Submit
5. 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.

Submit
6. 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.

Submit
7. Match the following:
Submit
8.
  1. 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.

Submit
9. Which is the best example of how to use braces when creating a conditional statement?

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.

Submit
10. 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.

Submit
11. 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.

Submit
12. To debug your code, the following methods are the best to use.

Explanation

random guessing is generally inefficient and time consuming.

Submit
13. 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.

Submit
14.  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.

Submit
15.
  1. 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.

Submit
16.
  1. Why should you use Comments tags?   Two primary reasons

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.

Submit
17. Greenfoot.getRandomNumber(8) + 1; Thid method would return numbers between ____ and 8

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

Submit
18. "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.

Submit
19. 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.

Submit
20. Translate source code into machine code that a computer can understand and execute.

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.

Submit
21. 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);

Submit
22. Mark all answers that are correct Write a method to show 50-50 probability

Explanation

The explanation for the given correct answer is that the expression "getRandomNumber(2)

Submit
23. 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());         }

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.

Submit
24. Greenfoot.getRandomNumber(10); This method  would return numbers from 0 to ____

Explanation

between 0 and 10 does not include 10.

Submit
25. 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.

Submit
26. A  __________________is a  mechanism used to pass additional data into a method. Example: public void move(distance);

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.

Submit
27. 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.

Submit
28. What is the method name for the following method? public void 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()".

Submit
29. A class called Ant extends the Actor class.

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".

Submit
30. Write a statement that will declare an integer instance variable called count and set its initial value to 0. (2 marks)

Explanation

Variables have a data type and name. You initialize the variable by setting it equal to a value.

Submit
31. Constructors can never have parameters.

Explanation

EX.
public Student(String parFirstName, String parLastName)
{
firstName = parFirstName;
lastName = parLastName;
}

Submit
32. This kind of error will allow your program to compile but will give you information that is wrong.

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.

Submit
33. 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)))

Explanation

The correct answer is the first option: if (Greenfoot.isKeyDown("D") || Greenfoot.isKeyDown("F") && (wormEaten >= 3) && (wormsEaten

Submit
34. If a class has subclasses, it is considered to be a _____________ class.

Explanation

super or parent class

Submit
35. 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.

Submit
36. 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.

Submit
37. On the following picture "void setDirection(int direction)" is called  the  ____________________  of the method.

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".

Submit
38. 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.

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.

Submit
39. Memory that belongs to the object that is used to store information(objects or values) for later use is called an ______________ variable. 

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.

Submit
40. /* */ 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.

Submit
41. Translate source code into byte code which the Java Interpreter (JVM – Java Virtual Machine) can understand.

Explanation

The process of translating source code into byte code that can be understood by the Java Interpreter (JVM) is called compilation.

Submit
42. Strings should be put in single quotes

Explanation

Double quotes

Submit
43.
  1. 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(  ___  ,  ___  ,  ___ );

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.

Submit
44. What is the return value of the following method: private boolean atWorldEdge()

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.

Submit
45. Use an ________________  variable when it exhibits a natural "has-a" relationship to the object

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.

Submit
46. What word is used to show that a class inherits methods and properties from a super class.

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.

Submit
47. The method "static int getRandomNumber(int limit)"   is from which class?

Explanation

The method "static int getRandomNumber(int limit)" is from the Greenfoot class.

Submit
48. Special methods that allow one to instantiate (construct) an object from a class.

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.

Submit
49. To straighten out your code and make it have proper indentations, you can use __________ from the Edit Menu.

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.

Submit
50. = 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.

Submit
51. 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  

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.

Submit
52. Write the method call for the method signature. (How would you call the method in your code?) public void 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.

Submit
53. 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.

Submit
54. What is the return value of the following method?        public void setSize(int sze)

Explanation

The return value of the given method is void. This means that the method does not return any value. It simply performs a task or operation without returning any result. In this case, the method "setSize" takes an integer parameter "sze" and does some operation or sets the size based on the given value, but it does not return any value after performing the operation.

Submit
55. "is-a" relationships between objects in classes is referred to as ____________________. For example a Crab "is an" Animal "is an" Actor.

Explanation

The given correct answer for this question is "inheritance". In object-oriented programming, "is-a" relationships between objects in classes are referred to as inheritance. This means that a subclass inherits the properties and behaviors of its superclass, allowing for code reuse and creating a hierarchical relationship between classes. In the given example, a Crab "is an" Animal, and an Animal "is an" Actor, demonstrating the concept of inheritance.

Submit
56. Readable English-like code written in a particular programming language

Explanation

The term "source code" refers to the readable English-like code written in a specific programming language. It is the original version of a program that is written by a programmer and can be understood by humans. This code is then compiled or interpreted to create the executable version of the program.

Submit
57. The best example for the correct way to name a class is

Explanation

The correct way to name a class is "BankAccount" because it follows the standard convention of using camel case notation for class names. In camel case, 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 class name more understandable for other programmers.

Submit
58. How many parameters does this method have? public void eat( )

Explanation

The method "eat( )" does not have any parameters. The absence of any input within the parentheses indicates that the method does not require any additional information to perform its task. Therefore, the correct answer is "none, None."

Submit
59. What keyword is common to all methods in the Greenfoot class that let us know they are class methods?

Explanation

The keyword "static" is common to all methods in the Greenfoot class that let us know they are class methods. Class methods are associated with the class itself rather than an instance of the class, and they can be called directly on the class without creating an object of the class. The "static" keyword is used to define class methods in Java, and it indicates that the method belongs to the class and not to any specific object.

Submit
60. What word do we always put at the front of an instance variable declaration?           

Explanation

In Java, the "private" keyword is used to declare an instance variable as private. This means that the variable can only be accessed within the same class and not from any other class. By putting "private" at the front of an instance variable declaration, we ensure that the variable is encapsulated and can only be modified or accessed through getter and setter methods within the class.

Submit
61. State the entire method signature of the addObject method of the World class.  

Explanation

The correct answer is "public void addObject(Actor object, int x, int y)". This is the correct method signature for the addObject method of the World class. It takes three parameters: an Actor object, and two integers x and y. The method is declared as public, meaning it can be accessed from outside the class, and it returns void, indicating that it does not return any value.

Submit
62. What is another name for instance variables?

Explanation

Instance variables are also commonly referred to as "fields". This term is used to describe the variables that are associated with each instance or object of a class. These variables hold the state or data of the object and can have different values for each instance. The terms "field" and "Instance variable" are often used interchangeably to describe the same concept in object-oriented programming.

Submit
63. In what method are the instance variables of the Crab class given their initial values?         

Explanation

The instance variables of the Crab class are given their initial values in the constructor method. The constructor is a special method that is called when an object of the class is created. It is used to initialize the instance variables of the class and perform any other setup tasks that are required. In this case, the constructor of the Crab class is responsible for setting the initial values of the instance variables.

Submit
64. What are the { } symbols called?

Explanation

The { } symbols are called curly brackets or braces. These symbols are used in programming languages to define blocks of code, indicate the beginning and end of functions, or to enclose sets and lists. They are also used in mathematical notation and in writing citations or references.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 31, 2012
    Quiz Created by
    Tcarteronw
Cancel
  • All
    All (64)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Check all places that you can get information to create methods in...
Match the following relational operators.
Match the following words with their corresponding definitions.
Match the following:
Methods that are void methods are like commands...
Void means the method does not return anything.
Match the following:
Suppose the method to call is defined in the same class or inherited...
Which is the best example of how to use braces when creating a...
Common characteristics of a constructor's signature. ...
A protected modier on a method means that the method...
To debug your code, the following methods are the best to use.
Methods that return a value are like questions....
 We know which format to use when declaring a methodName by...
Suppose the method is not in the same class or inherited from another...
Why should you use Comments tags?   Two primary reasons
Greenfoot.getRandomNumber(8) + 1;...
"Functions" are represented by Java methods whose returnType is not...
The terminal window appears automatically when the first...
Translate source code into machine code that a computer can understand...
SetLocation(100, 150);...
Mark all answers that are correct...
Complete this for loop that would create 5 different Worms...
Greenfoot.getRandomNumber(10);...
You do not have to use dot notation is a method is in the same class...
A  __________________is a  mechanism used to pass additional...
Comments that describe your code are often concise and begin with...
What is the method name for the following method? public void eat()
A class called Ant extends the Actor class.
Write a statement that will declare an integer instance variable...
Constructors can never have parameters.
This kind of error will allow your program to compile but will give...
Write an if statement that would  play a sound when the "D" key...
If a class has subclasses, it is considered to be a _____________...
You do not have to use dot notation if a method is inherited.
Constructors do not have the same name as the class.
On the following picture "void setDirection(int direction)"...
What kind of error will keep your program from compiling? ...
Memory that belongs to the object that is used to store...
/* */ These tags are for single line code comments
Translate source code into byte code which the Java Interpreter (JVM...
Strings should be put in single quotes
You want the dimensions of the world in your Greenfoot scenario to be...
What is the return value of the following method:...
Use an ________________  variable when it exhibits a natural...
What word is used to show that a class inherits methods and properties...
The method "static int getRandomNumber(int limit)"   is...
Special methods that allow one to instantiate (construct) an object...
To straighten out your code and make it have proper indentations, you...
= is used as a Boolean statement to determine if something is true or...
Attempt to always use( local or instance )  variables except when...
Write the method call for the method signature. ...
If (atWorldEdge());...
What is the return value of the following method?...
"is-a" relationships between objects in classes is referred to as...
Readable English-like code written in a particular programming...
The best example for the correct way to name a class is
How many parameters does this method have? public void eat( )
What keyword is common to all methods in the Greenfoot class that let...
What word do we always put at the front of an instance variable...
State the entire method signature of the addObject method of the World...
What is another name for instance variables?
In what method are the instance variables of the Crab class given...
What are the { } symbols called?
Alert!

Advertisement