Greenfoot Ch 1- 4

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Tcarteronw
T
Tcarteronw
Community Contributor
Quizzes Created: 38 | Total Attempts: 29,972
Questions: 64 | Attempts: 1,102

SettingsSettingsSettings
Greenfoot Ch 1- 4 - Quiz

Test over Ch 1-4 programs, notes, and code.


Questions and Answers
  • 1. 

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

    • A.

      Object

    • B.

      Method

    • C.

      Instance

    • D.

      Signature

    Correct Answer
    D. 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:

  • 2. 

    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:

  • 3. 

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

    • A.

      True

    • B.

      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:

  • 4. 

    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:

  • 5. 

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

    Correct Answer
    inheritance
    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.

    Rate this question:

  • 6. 

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

    • A.

      True

    • B.

      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:

  • 7. 

    Void means the method does not return anything.

    • A.

      True

    • B.

      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:

  • 8. 

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

    • A.

      True

    • B.

      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:

  • 9. 

    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:

  • 10. 

    Readable English-like code written in a particular programming language

    Correct Answer
    source code
    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.

    Rate this question:

  • 11. 

    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:

  • 12. 

    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:

  • 13. 

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

    Correct Answer
    void
    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.

    Rate this question:

  • 14. 

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

    Correct Answer
    none
    None
    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."

    Rate this question:

  • 15. 

    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:

  • 16. 

    A class called Ant extends the Actor class.

    • A.

      Ant is a super class to Actor

    • B.

      Actor is the super class to Ant

    • C.

      Actor is not a class

    Correct Answer
    B. 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:

  • 17. 

    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:

  • 18. 

    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:

  • 19. 

    What are the { } symbols called?

    • A.

      Braces

    • B.

      Curly brackets

    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.

    Rate this question:

  • 20. 

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

    • A.

      BankAccount

    • B.

      Bank account

    • C.

      BankAccount

    • D.

      Bank_Account

    Correct Answer
    C. BankAccount
    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.

    Rate this question:

  • 21. 

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

    • A.

      Greenfoot help menu

    • B.

      Java documentation

    • C.

      Greenfoot documentation

    • D.

      Greenfoot web site

    Correct Answer(s)
    A. Greenfoot help menu
    B. Java documentation
    C. Greenfoot documentation
    D. Greenfoot web site
    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.

    Rate this question:

  • 22. 

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

    • A.

      True

    • B.

      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:

  • 23. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 24. 

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

    • A.

      True

    • B.

      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:

  • 25. 

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

    • A.

      True

    • B.

      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:

  • 26. 

    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:

  • 27. 

    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:

  • 28. 

    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:

  • 29. 

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

    • A.

      To explain code you are writing

    • B.

      To check for errors

    • C.

      It makes your code prettier

    Correct Answer(s)
    A. To explain code you are writing
    B. 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:

  • 30. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    B. 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:

  • 31. 

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

    • A.

      True

    • B.

      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:

  • 32. 

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

    • A.

      Use the debugger and set breakpoints

    • B.

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

    • C.

      Randomly guess and fix it by trial and error

    Correct Answer(s)
    A. Use the debugger and set breakpoints
    B. Use "System.out.println" to output information you would like to check
    Explanation
    random guessing is generally inefficient and time consuming.

    Rate this question:

  • 33. 

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

    • A.

      True

    • B.

      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:

  • 34. 

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

    • A.

      If (condition) { statement(s); }

    • B.

      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:

  • 35. 

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

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 36. 

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

    • A.

      Public count = 0;

    • B.

      Public int count = 0;

    • C.

      Public void count = 0;

    • D.

      Public void count();

    Correct Answer
    B. 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:

  • 37. 

    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:

  • 38. 

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

    Correct Answer
    9
    Explanation
    between 0 and 10 does not include 10.

    Rate this question:

  • 39. 

    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:

  • 40. 

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

    Correct Answer
    static
    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.

    Rate this question:

  • 41. 

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

    Correct Answer
    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:

  • 42. 

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

    • A.

      GetRandomNumber(2) < 1

    • B.

      GetRandomNumber(100) < 50

    • C.

      GetRandomNumber(50) < 50

    Correct Answer(s)
    A. GetRandomNumber(2) < 1
    B. 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:

  • 43. 

    Strings should be put in single quotes

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Double quotes

    Rate this question:

  • 44. 

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

    • A.

      True

    • B.

      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:

  • 45. 

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

    • A.

      True

    • B.

      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:

  • 46. 

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

    Correct Answer
    super
    parent
    Explanation
    super or parent class

    Rate this question:

  • 47. 

    Constructors can never have parameters.

    • A.

      True

    • B.

      False

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

    Rate this question:

  • 48. 

    Constructors do not have the same name as the class.

    • A.

      False

    • B.

      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:

  • 49. 

    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

    • A.

      True

    • B.

      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:

  • 50. 

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

    • A.

      Public void addObject(new Actor(), x, y)

    • B.

      AddObject(new Actor(), x, y)

    • C.

      Public void addObject(Actor object, int x, int y)

    Correct Answer
    C. Public void addObject(Actor object, int x, int y)
    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.

    Rate this question:

Quiz Review Timeline +

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.