Anatomy of a Class - AP Computer Science A

  1. What is the signature of a method?
    The method's name and parameter list. Identifies method for compilation and overriding.
  2. What is a method in a Java class?
    A block of code that performs a specific task. Defines behavior that objects can perform.
  3. Identify the superclass of all classes in Java.
    Object. Root class that all Java classes inherit from.
  4. What is the main purpose of a Java interface?
    To specify methods that a class must implement. Enforces method contracts without implementation.
  5. What is an abstract class?
    A class that cannot be instantiated and may contain abstract methods. Serves as template requiring subclass implementation.
  6. What is the static keyword used for?
    To define class-level fields and methods. Belongs to class rather than instances.
  7. What is a class in Java?
    A blueprint for creating objects, defining fields and methods. Encapsulates data and behavior for object creation.
  8. What is the purpose of a constructor?
    To initialize a new object of a class. Sets initial values for object fields.
  9. What is method overloading?
    Defining multiple methods with the same name but different parameters. Same name, different parameter signatures.
  10. Which keyword prevents a class from being subclassed?
    final. Prevents inheritance to maintain class integrity.
  11. Which keyword is used to implement an interface?
    implements. Establishes contract between class and interface.
  12. What is the difference between == and equals()?
    == checks reference; equals() checks value equality. Reference vs content comparison distinction.
  13. Which keyword is used to declare an abstract class?
    abstract. Prevents direct instantiation of the class.
  14. What is the purpose of the 'this' keyword?
    Refers to the current instance of a class. Distinguishes between instance and parameter variables.
  15. What is polymorphism in Java?
    The ability to process objects differently based on their data type. Enables one interface with multiple implementations.
  16. Identify the method that is automatically called when an object is created.
    Constructor. Invoked immediately upon object instantiation.
  17. What is encapsulation in Java?
    Hiding data fields using access modifiers. Core OOP principle for data protection.
  18. Identify the keyword to declare a constant in Java.
    final. Makes fields or variables unchangeable after initialization.
  19. What is inheritance in Java?
    A mechanism where one class acquires the properties of another. Child class gains parent's properties and methods.
  20. Identify the keyword used to import a package.
    import. Makes external classes available in current file.
  21. Which access modifier restricts visibility to the containing class?
    private. Most restrictive access level for data hiding.
  22. What is a field in a Java class?
    A variable declared within a class. Stores data as part of an object's state.
  23. What is an object in the context of Java?
    An instance of a class containing fields and methods. A concrete realization of a class template.
  24. Which method is used to compare two objects for equality?
    equals(). Compares object content rather than references.
  25. Which access modifier allows visibility within the same package only?
    default (no modifier). Package-private access when no modifier specified.
  26. What is a package in Java?
    A namespace that organizes classes and interfaces. Groups related classes for organization.
  27. Which keyword is used to create an object in Java?
    new. Allocates memory and invokes the constructor.
  28. Identify the default value of an int field in Java.
    0. Numeric primitives initialize to zero by default.
  29. Can a Java class implement multiple interfaces?
    Yes, a class can implement multiple interfaces. Multiple inheritance through interfaces is allowed.
  30. What does the keyword 'super' refer to in Java?
    The superclass of the current object. Accesses parent class members and methods.
  31. What is method overriding?
    Redefining a method in a subclass that exists in the superclass. Child class replaces parent's method implementation.
  32. What is the default value of a boolean field in Java?
    false. Primitive types initialize to false automatically.
  33. Identify the method that initializes an object.
    Constructor. Special method that sets up new object instances.
  34. Identify the keyword used to declare a class in Java.
    class. The reserved word that starts all class definitions.
  35. Which keyword is used to invoke a superclass's constructor?
    super. Calls parent constructor or method explicitly.
  36. What keyword is used to inherit from a class?
    extends. Creates parent-child relationship between classes.
  37. Identify the method that returns a string representation of an object.
    toString(). Provides readable format for object display.
  38. Which access modifier allows visibility to all classes?
    public. Provides unrestricted access from anywhere.

Study these flashcards