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: 31,789
| Attempts: 1,173
SettingsSettings
Please wait...
  • 1/64 Questions

    Check all places that you can get information to create methods in Greenfoot

    • Greenfoot help menu
    • Java documentation
    • Greenfoot documentation
    • Greenfoot web site
Please wait...
Greenfoot Ch 1- 4 - Quiz
About This 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 as inheritance, crucial for beginners in computer science.


Quiz Preview

  • 2. 

    Methods that are void methods are like commands Example: public void move()

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 3. 

    Void means the method does not return anything.

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 4. 

    1. Suppose the method to call is defined in the same class or inherited from another class
    In general, the format is: methodName(parameters…)

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 5. 

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

    • If (condition) { statement(s); }

    • If (condition) statement(s);

    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.

    Rate this question:

  • 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

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 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

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 8. 

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

    • Use the debugger and set breakpoints

    • Use "System.out.println" to output information you would like to check

    • Randomly guess and fix it by trial and error

    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.

    Rate this question:

  • 9. 

    Methods that return a value are like questions. Example: public boolean canMove()

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 10. 

     We know which format to use when declaring a methodName by checking for the static keyword.

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 11. 

    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…)

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 12. 

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

    • To explain code you are writing

    • To check for errors

    • It makes your code prettier

    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.

    Rate this question:

  • 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

    Rate this question:

  • 14. 

    “Functions” are represented by Java methods whose returnType is not void.

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 15. 

    The terminal window appears automatically when the first System.out.println statement is executed.

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

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

    Rate this question:

  • 17. 

    SetLocation(100, 150); The parameters of 100 and 150 tell you that  the y coordinate is 100 and the x coordinate is 150.

    • True

    • False

    Correct Answer
    A. False
    Explanation
    setLocation(int x, int y);

    Rate this question:

  • 18. 

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

    • GetRandomNumber(2) < 1

    • GetRandomNumber(100) < 50

    • GetRandomNumber(50) < 50

    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.

    Rate this question:

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

    Rate this question:

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

    Rate this question:

  • 21. 

    You do not have to use dot notation is a method is in the same class you are writing the method in.

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

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

    Rate this question:

  • 23. 

    Comments that describe your code are often concise and begin with action words. Assume the reader of your code already understands the language.

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 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()".

    Rate this question:

  • 25. 

    A class called Ant extends the Actor class.

    • Ant is a super class to Actor

    • Actor is the super class to Ant

    • Actor is not a 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".

    Rate this question:

  • 26. 

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

    • Public count = 0;

    • Public int count = 0;

    • Public void count = 0;

    • Public void count();

    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.

    Rate this question:

  • 27. 

    Constructors can never have parameters.

    • True

    • False

    Correct Answer
    A. False
    Explanation
    EX.
    public Student(String parFirstName, String parLastName)
    {
    firstName = parFirstName;
    lastName = parLastName;
    }

    Rate this question:

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

    Rate this question:

  • 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)))

    • If (Greenfoot.isKeyDown(“D”) || Greenfoot.isKeyDown(“F”) &&( wormEaten >= 3) && (wormsEaten

    • If (Greenfoot.isKeyDown(“D”) && Greenfoot.isKeyDown(“F”) ||( wormEaten >= 3) || (wormsEaten

    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

    Rate this question:

  • 30. 

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

    Correct Answer
    super
    parent
    Explanation
    super or parent class

    Rate this question:

  • 31. 

    You do not have to use dot notation if a method is inherited.

    • True

    • False

    Correct Answer
    A. True
    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.

    Rate this question:

  • 32. 

    Constructors do not have the same name as the class.

    • False

    • True

    Correct Answer
    A. False
    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.

    Rate this question:

  • 33. 

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

    • Object

    • Method

    • Instance

    • Signature

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

    Rate this question:

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

    Rate this question:

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

    Rate this question:

  • 36. 

    /* */ These tags are for single line code comments

    • True

    • False

    Correct Answer
    A. False
    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.

    Rate this question:

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

    Rate this question:

  • 38. 

    Strings should be put in single quotes

    • True

    • False

    Correct Answer
    A. False
    Explanation
    Double quotes

    Rate this question:

  • 39. 

    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(  ___  ,  ___  ,  ___ );

    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.

    Rate this question:

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

    Rate this question:

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

    Rate this question:

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

    Rate this question:

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

    Rate this question:

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

    Rate this question:

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

    Rate this question:

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

    • True

    • False

    Correct Answer
    A. False
    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.

    Rate this question:

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

    Rate this question:

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

    Rate this question:

  • 49. 

    If (atWorldEdge()); This is the correct way to write the if conditional.

    • True

    • False

    Correct Answer
    A. False
    Explanation
    It should never have a " ; " at the end of the condition. It stops the statements from executing.

    Rate this question:

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.