Objects: Instances of Classes - AP Computer Science A
- Which operator is used to check if two references point to the same object?
- ==. Tests reference equality, not object content comparison.
- Identify the keyword used to inherit from another class.
- extends. Establishes parent-child relationship between classes for code reuse.
- Identify the method used to initialize an object in Java.
- Constructor. Constructors set initial values for object instance variables.
- What is the significance of the 'protected' access modifier?
- Accessible within package and subclasses. Allows package and subclass access while restricting others.
- Identify the collection that does not allow duplicate elements.
- Set. Mathematical set behavior ensures unique element storage.
- What is method overriding?
- Subclass provides specific implementation of a method already defined in its superclass. Allows customized behavior while maintaining same method signature.
- What is the purpose of a constructor?
- Initialize an object. Sets up initial state and prepares object for use.
- What is the main benefit of using interfaces?
- Support multiple inheritance of type. Classes can implement multiple interfaces for flexible design.
- Which keyword is used to refer to the current instance of a class?
- this. References the specific object calling the method or constructor.
- 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.
- What is encapsulation in object-oriented programming?
- Hiding internal state and requiring all interaction through methods. Protects data integrity by controlling access through methods.
- What is the return type of a constructor?
- No return type. Constructors initialize objects but don't return values.
- Identify the method that returns a string representation of an object.
- toString(). Provides readable text representation for debugging and display.
- What is the default value of an object reference in Java?
- null. Uninitialized object references automatically default to null value.
- Which keyword is used to declare a constant in Java?
- final. Makes variables immutable after initial assignment.
- Which collection allows duplicate elements?
- List. Ordered collections that maintain insertion order and duplicates.
- 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.
- What is method overloading?
- Multiple methods with the same name but different parameters. Enables method reuse with different parameter combinations.
- 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.
- What makes a method abstract?
- Declared without an implementation. Must be implemented by concrete subclasses to provide functionality.
- What is an abstract class?
- A class that cannot be instantiated and may contain abstract methods. Serves as template requiring subclasses to implement methods.
- Which access modifier makes a class member accessible from any other class?
- public. Provides unrestricted access across all classes and packages.
- Which keyword is used to create an object in Java?
- new. The 'new' keyword allocates memory and calls the constructor.
- 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.
- Which function is used to compare two objects for equality?
- equals(). Compares object content rather than reference addresses.
- 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.
- 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.
- What does the 'this' keyword represent in a class?
- Current object instance. Allows access to current object's fields and methods within class.
- Identify the keyword used to implement an interface.
- implements. Establishes contract between interface and implementing class.
- 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.
- How do you access a class variable?
- ClassName.variableName. Static variables belong to class, accessed via class name.
- What is an object in Java?
- An instance of a class. Objects are concrete realizations of classes with specific data values.
- Which keyword is used to define an interface?
- interface. Defines contracts that implementing classes must fulfill.
- What is the purpose of the 'super' keyword?
- Access parent class methods and constructors. Enables access to inherited functionality from parent class.
- What is the process of creating an object called?
- Instantiation. The act of creating a specific object from a class blueprint.
- Which method is called automatically when an object is created?
- Constructor. Constructors execute automatically during object creation process.
- Identify the keyword that prevents a class from being subclassed.
- final. Prevents inheritance by making class non-extendable.
- 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.