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