Game Preview

PR1-W6-Part1-OOP_Classes&Objects

  •  English    24     Public
    PR1-W6-Part1-OOP_Classes&Objects
  •   Study   Slideshow
  • 1. Which Java keyword is used to create a new object (an instance) of a class? (1)
    C. new (Example: Dog d = new Dog();)
  •  15
  • 2. Which of the following is not a primitive type in Java? (1)
    C. String
  •  15
  • 3. What does a class represent in object-oriented programming? (1)
    B (A class defines fields and methods. Instances (objects) are created from that blueprint.)
  •  15
  • 4. Which statement about the main method is correct? (2)
    B (JVM calls public static void main(String[] args) without creating an object, so main is static)
  •  15
  • 5. Which of the following best describes encapsulation? (2)
    B (Encapsulation uses private fields and public getters/setters or methods to control access)
  •  10
  • 6. What is the output? (2)
    5 (int is primitive → assignment copies the value. Changing y does not affect x.)
  •  20
  • 7. What is the output? (2)
    Fido (d1 and d2 refer to the same object → changing through one affects the other.)
  •  20
  • 8. What happens? (3)
    Compile error (No default constructor is available since the class declared a constructor with parameters)
  •  20
  • 9. What is printed? (3)
    70.0 (Withdraw subtracts from balance, leaving 70)
  •  25
  • 10. What is the output? (3)
    2 (Static field count is shared across all objects. Each constructor increments once)
  •  20
  • 11. Which keyword refers to the current instance inside an instance method or constructor? (2)
    C. this
  •  10
  • 12. Which is true about static fields? (2)
    B (Only one copy of a static field exists per class loader; all instances share it)
  •  10
  • 13. What does the expression a == b test when a and b are object references? (3)
    B ( == compares references for objects. equals() can be overridden to compare content.)
  •  15
  • Won 25 points
    25
  •  25
  • 14. Which statement about equals() is correct? (3)
    B (Object.equals() tests this == obj. Many classes (e.g., String) override it to compare content)
  •  20
  • 15. Given String s1 = "hi"; String s2 = "hi";, what is s1 == s2? (3)
    B ( String literals are interned; identical literals refer to the same object in the string pool, so == is true)
  •  10