Fundamentals Final (Ch 1-7)

60 Questions | Total Attempts: 93

SettingsSettingsSettings
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