Objects: Instances of Classes - AP Computer Science A

  1. Which operator is used to check if two references point to the same object?
    ==. Tests reference equality, not object content comparison.
  2. Identify the keyword used to inherit from another class.
    extends. Establishes parent-child relationship between classes for code reuse.
  3. Identify the method used to initialize an object in Java.
    Constructor. Constructors set initial values for object instance variables.
  4. What is the significance of the 'protected' access modifier?
    Accessible within package and subclasses. Allows package and subclass access while restricting others.
  5. Identify the collection that does not allow duplicate elements.
    Set. Mathematical set behavior ensures unique element storage.
  6. What is method overriding?
    Subclass provides specific implementation of a method already defined in its superclass. Allows customized behavior while maintaining same method signature.
  7. What is the purpose of a constructor?
    Initialize an object. Sets up initial state and prepares object for use.
  8. What is the main benefit of using interfaces?
    Support multiple inheritance of type. Classes can implement multiple interfaces for flexible design.
  9. Which keyword is used to refer to the current instance of a class?
    this. References the specific object calling the method or constructor.
  10. What is the result of calling a constructor with no arguments?
    Default constructor is invoked. Creates object with default field values when no parameters given.
  11. What is encapsulation in object-oriented programming?
    Hiding internal state and requiring all interaction through methods. Protects data integrity by controlling access through methods.
  12. What is the return type of a constructor?
    No return type. Constructors initialize objects but don't return values.
  13. Identify the method that returns a string representation of an object.
    toString(). Provides readable text representation for debugging and display.
  14. What is the default value of an object reference in Java?
    null. Uninitialized object references automatically default to null value.
  15. Which keyword is used to declare a constant in Java?
    final. Makes variables immutable after initial assignment.
  16. Which collection allows duplicate elements?
    List. Ordered collections that maintain insertion order and duplicates.
  17. What does 'instance variable' mean?
    A variable defined in a class for which each instantiated object has its own value. Each object maintains its own copy of these variables.
  18. What is method overloading?
    Multiple methods with the same name but different parameters. Enables method reuse with different parameter combinations.
  19. What is polymorphism in object-oriented programming?
    Ability of different classes to be treated as instances of the same class through inheritance. Enables single interface to represent different underlying types.
  20. What makes a method abstract?
    Declared without an implementation. Must be implemented by concrete subclasses to provide functionality.
  21. What is an abstract class?
    A class that cannot be instantiated and may contain abstract methods. Serves as template requiring subclasses to implement methods.
  22. Which access modifier makes a class member accessible from any other class?
    public. Provides unrestricted access across all classes and packages.
  23. Which keyword is used to create an object in Java?
    new. The 'new' keyword allocates memory and calls the constructor.
  24. What is the difference between an ArrayList and an array?
    ArrayList is resizable, array has fixed size. ArrayList grows dynamically while arrays have compile-time size.
  25. Which function is used to compare two objects for equality?
    equals(). Compares object content rather than reference addresses.
  26. What type of method can only be called from an instance of the class?
    Instance method. Non-static methods require object instance to be invoked.
  27. What is a class method in Java?
    A method that belongs to the class, rather than any object instance. Static methods can be called without creating object instances.
  28. What does the 'this' keyword represent in a class?
    Current object instance. Allows access to current object's fields and methods within class.
  29. Identify the keyword used to implement an interface.
    implements. Establishes contract between interface and implementing class.
  30. What does the 'static' keyword indicate about a method or variable?
    Belongs to the class, not any instance. Shared across all instances rather than per-object storage.
  31. How do you access a class variable?
    ClassName.variableName. Static variables belong to class, accessed via class name.
  32. What is an object in Java?
    An instance of a class. Objects are concrete realizations of classes with specific data values.
  33. Which keyword is used to define an interface?
    interface. Defines contracts that implementing classes must fulfill.
  34. What is the purpose of the 'super' keyword?
    Access parent class methods and constructors. Enables access to inherited functionality from parent class.
  35. What is the process of creating an object called?
    Instantiation. The act of creating a specific object from a class blueprint.
  36. Which method is called automatically when an object is created?
    Constructor. Constructors execute automatically during object creation process.
  37. Identify the keyword that prevents a class from being subclassed.
    final. Prevents inheritance by making class non-extendable.
  38. What does 'inheritance' mean in object-oriented programming?
    A class inherits fields and methods from another class. Promotes code reuse by sharing parent class features.

Study these flashcards