Fundamentals Final (ch 1-7)

60 Questions

Settings
Please wait...
Data Structure Quizzes & Trivia

Questions and Answers
  • 1. 
    This is how you create a Java multi-line comment to place the following into a comment. /* Replace the image on the screen and then move it right 10 pixels */
    • A. 

      True

    • B. 

      False

  • 2. 
    Suppose you are given a variable named temperature that holds a value. This is how you would write an if-else statement that will display Above Freezing if temperature is greater than 32, Freezing if temperature is equal to 32, else it will display At or Below Freezing. if (temperature > 32) System.out.println("Above Freezing"); else (temperature == 32) System.out.println("Freezing"); else System.out.println("At or Below Freezing");
    • A. 

      True

    • B. 

      False

  • 3. 
    Simplify the following expressions to either true or false: Given: x is an integer variable holding the value 3 y is an integer variable holding the value -5 z is an integer variable holding the value -4 (x > z) || (y < z) && !(y < x)
    • A. 

      True

    • B. 

      False

  • 4. 
    True of False. Java is not case-sensitive
    • A. 

      True

    • B. 

      False

  • 5. 
    This is how you write an if-else statement that will display JCCC 45% of the time, else it will display Cavaliers. if (Greenfoot.getRandomNumber(100) < 45)     System.out.println("JCCC"); else     System.out.println("Cavaliers");
    • A. 

      True

    • B. 

      False

  • 6. 
    Write a statement that will declare an integer instance variable called count and set its initial value to 0.
    • A. 

      Public int count = 0;

    • B. 

      Public count = 0;

    • C. 

      Public void count();

  • 7. 
    To pass additional data to a method we specify a
    • A. 

      Return type

    • B. 

      Name

    • C. 

      Parameter

    • D. 

      Parenthesis

  • 8. 
    A compiler
    • A. 

      Translates source code into executable code

    • B. 

      Tests a program's logic

    • C. 

      Translates executable code to machine code

    • D. 

      Maintains a collection of programs

  • 9. 
    In object-oriented programming a class is
    • A. 

      A group of people sharing the same relationship to the means of production.

    • B. 

      A procedure for a calculation inside a program.

    • C. 

      The term used for programs

    • D. 

      A model or template from which objects are created

  • 10. 
    Write one statement that declares a local variable named city and initializes it to Overland Park.
    • A. 

      String city = “Overland Park”;

    • B. 

      String[“Overland Park];

    • C. 

      City = “Overland Park”;

  • 11. 
    The best example for the correct way to name a class is
    • A. 

      Bank account

    • B. 

      BankAccount

    • C. 

      Bank_Account

    • D. 

      BankAccount

  • 12. 
    Write a method signature for a method named "randomMove". The method has no parameters, and it does not return a value.
    • A. 

      Public randomMove()

    • B. 

      Public void randomMove()

    • C. 

      Public void randomMove

  • 13. 
    What the value of x is at the end:        int i=0;      int x=0;             while (i < 4)         {             x = x + i;             i++;         }
    • A. 

      1

    • B. 

      2

    • C. 

      3

    • D. 

      4

  • 14. 
    Given the following variable declarations, evaluate the following Boolean expression: int a= 7; int b = 12; int c = 12; int d = 7; (a ==c ||a ==b)
    • A. 

      True

    • B. 

      False

  • 15. 
    Variable Declarations need a data type and a variable name
    • A. 

      True

    • B. 

      False

  • 16. 
    Which of the following is not a data type in Java?
    • A. 

      Int

    • B. 

      Double

    • C. 

      Boolean

    • D. 

      String

    • E. 

      Constant

  • 17. 
    An identifier can be named in Java using letters, digits, underscores and the $ sign.  They may not begin with an underscore.
    • A. 

      True

    • B. 

      False

  • 18. 
    Mark the following identifiers that are valid names to use in Java.
    • A. 

      7days

    • B. 

      _days

    • C. 

      NumDays

    • D. 

      $days

    • E. 

      Num.days

  • 19. 
    Which is the best declaration for  a variable that will hold monthly rainfall. It is initialized to 0?
    • A. 

      Float totalMonthlyRainfall = 0.0 ;

    • B. 

      Int totalMonthlyRainfall = 0;

    • C. 

      Float totalMonthlyRainfall;

    • D. 

      Int totalMonthlyRainfall;

  • 20. 
    Practice with logical operators Given: int age1 = 21; int age2 = 14; int age3 = 15; int birth = 0; String name = “JCCC”; age1 < age2 && age2 < age3
    • A. 

      True

    • B. 

      False

  • 21. 
    Given the code below, what are the local variables? public class MathStudent extends Actor {     protected String firstName;     protected String lastName;         public MathStudent()     {         firstName = "";         lastName = "";     }       public void countToFive()     {         int i = 1;         int limit = 5;         while (i <= 5)         {           System.out.println(i);           i = i + 1;         }     } }
    • A. 

      FirstName, lastName

    • B. 

      Limit, i

    • C. 

      FirstName, lastName, limit, i

  • 22. 
    Mark the arrays that are declared correctly by good programming standard.
    • A. 

      Int[] scores;

    • B. 

      Int scores [];

    • C. 

      Float[] rates;

    • D. 

      Float rates [];

  • 23. 
    Declare and create a new array of 5 elements for a scores array.
    • A. 

      Int[] scores = new int[5];

    • B. 

      Int[5] scores = new int[];

    • C. 

      Int scores = new int[5];

  • 24. 
    Write a line of code to change the element at index 3 to 5 in the scores array.
    • A. 

      Scores[3] = 5;

    • B. 

      Scores[5] = 0;

    • C. 

      Scores[5] = 5;

  • 25. 
    Objects are created from
    • A. 

      Methods

    • B. 

      Classes

    • C. 

      Parameters

    • D. 

      Commands

  • 26. 
    Objects have several ___________ that are blocks of code that perform specific tasks or actions.
    • A. 

      Methods

    • B. 

      Classes

    • C. 

      Instances

    • D. 

      Parameters

  • 27. 
    This specifies what type of data a method call with return:
    • A. 

      Parameters

    • B. 

      Commands

    • C. 

      Class type

    • D. 

      Return type

  • 28. 
    The mechanism that is used to pass additional information to a method is called a:
    • A. 

      Command

    • B. 

      Parameter

    • C. 

      Return type

    • D. 

      Signature

  • 29. 
    The specification of a method, which shows its return type, name and parameters is called its:
    • A. 

      Command

    • B. 

      Parameter

    • C. 

      Return type

    • D. 

      Signature

  • 30. 
    Another name for an objects is an:
    • A. 

      Class

    • B. 

      Command

    • C. 

      Method

    • D. 

      Instance

  • 31. 
    An instruction that tells an object to perform a specific task it has programming code to do is called a:
    • A. 

      Parameter

    • B. 

      Command

    • C. 

      Method call

    • D. 

      Instance

  • 32. 
    The command that allows you to make a decision based on true or false conditions is a(n):
    • A. 

      List command

    • B. 

      Do command

    • C. 

      Act statement

    • D. 

      If statement

  • 33. 
    When you need to call a method from a different class you must specify the class name before the method name using:
    • A. 

      Dot notation

    • B. 

      Parenthetical citation

    • C. 

      Curly braces

    • D. 

      Spaces

  • 34. 
    Methods that belong to the class itself are marked with the keyword:
    • A. 

      Void

    • B. 

      Public

    • C. 

      Static

    • D. 

      General

  • 35. 
    By convention, class names in Java should always start with a:
    • A. 

      Capital letter

    • B. 

      Small letter but use capital letters for the beginning of words in the middle of it

  • 36. 
    This default Greenfoot method is automatically created in each new class and is what is executed when you click on Act or Run in the window:
    • A. 

      CanSee()

    • B. 

      Move()

    • C. 

      Run()

    • D. 

      Act()

  • 37. 
    Comments are ignored by the computer but necessary for documentation for the user and they are started with:
    • A. 

      /**

    • B. 

      (

    • C. 

      {

    • D. 

  • 38. 
    By convention, method names in Java should always start with a:
    • A. 

      Capital letter

    • B. 

      Small letter but use capital letters for the beginning of words with no spaces (camel casing)

  • 39. 
    A bit of memory that belongs to an object to store information is called a:
    • A. 

      Method call

    • B. 

      Instance variable

    • C. 

      Return type

  • 40. 
    Good Java coding practice dictates that we should declare all of our variables:
    • A. 

      At the top of the class

    • B. 

      Inside of the method that it is going to be used in

    • C. 

      At the end of the class

  • 41. 
    An assignment statement enables us to store something into a variable.  The symbol that allows us to do that is:
    • A. 

      !=

    • B. 

      =

    • C. 

      ==

    • D. 

      /=

  • 42. 
    This statement  can be added to the IF statement to specify what should happen if the condition is false:
    • A. 

      When

    • B. 

      While

    • C. 

      Do

    • D. 

      Else

  • 43. 
    Putting this symbol in front of something means NOT:
    • A. 

      . (dot

    • B. 

      ! (exclamation mark)

    • C. 

      ^(caret)

    • D. 

      –(dash)

  • 44. 
    These symbols mean AND, which will join two conditions:
    • A. 

      &&

    • B. 

      !!

    • C. 

      ||

    • D. 

  • 45. 
    When we need to repeat code or do a similar task repeatedly, we need a:
    • A. 

      Constant

    • B. 

      Loop

    • C. 

      Modifier

    • D. 

      Instance

  • 46. 
    This type of data structure allows us to store many values of the same type and access them using an index, like this whiteKeys[2], which would access the third element:
    • A. 

      String

    • B. 

      Array

    • C. 

      Double

    • D. 

      Constant

  • 47. 
    A special expression that means “nothing” or “no object” is:
    • A. 

      Null

    • B. 

      Private

    • C. 

      Static

    • D. 

      Boolean

  • 48. 
     A method with a void return type does not return a value.  
    • A. 

      True

    • B. 

      False

  • 49. 
    Actors are classes that are placed into the world
    • A. 

      True

    • B. 

      False

  • 50. 
    Computers do not understand source code that we type in so it needs to be translated into machine code by a compiler before being executed.
    • A. 

      True

    • B. 

      False

  • 51. 
    Java is very case dependent, so Body and body represent two different things.
    • A. 

      True

    • B. 

      False

  • 52. 
    Objects will inherit methods from its superclasses.
    • A. 

      True

    • B. 

      False

  • 53. 
    Anything stored in an instance variable will be remembered as long as the object exists and can be accessed later.
    • A. 

      True

    • B. 

      False

  • 54. 
    A constant is a named value that is used like a variable, but can only be  changed by other classes.
    • A. 

      True

    • B. 

      False

  • 55. 
    Methods with void return types represent
    • A. 

      Commands

    • B. 

      Questions