1/28
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Class
A blueprint or template for creating objects that defines attributes (fields) and behaviors (methods).
Object
An instance of a class that contains its own unique data and can perform actions defined by the class.
Field (Attribute)
A variable declared inside a class but outside any method, used to store data about an object.
Method
A function defined inside a class that performs operations or actions on the object’s data.
Constructor
A special method used to initialize new objects of a class; has the same name as the class and no return type.
Default Constructor
A no-argument constructor automatically provided by Java if no constructor is explicitly defined.
Parameterized Constructor
A constructor that accepts arguments to initialize object fields with specific values
Overloaded Constructor
Multiple constructors in the same class with different parameter lists, allowing varied ways to initialize objects
Encapsulation
The practice of hiding internal data using private fields and providing controlled access through public methods
Access Modifier
Keywords that control visibility of class members: public, private, protected, or default (package-private)
Public Access Modifier
Allows the member or class to be accessible from anywhere in the program
Private Access Modifier
Restricts access to within the same class; used to protect object data
Protected Access Modifier
Allows access within the same package and by subclasses
Getter Method
A public method that returns the value of a private field (e.g., getName())
Setter Method
A public method that modifies a private field, often with input validation (e.g., setAge(int a))
this Keyword
Refers to the current object instance; used to distinguish between instance variables and parameters
Static Field
A variable shared by all instances of a class, belonging to the class rather than individual objects.
Static Method
A method that belongs to the class instead of instances; called using the class name (e.g., Math.sqrt(9)).
Composition
A relationship where one class contains another as a field, representing a “has-a” relationship (e.g., a Car has an Engine)
Class Naming Convention
Class names should begin with a capital letter and use CamelCase (e.g., BankAccount, StudentRecord).
Method Naming Convention
Methods use lowerCamelCase (e.g., calculateTotal, printReceipt).
Field Naming Convention
Fields typically use lowerCamelCase (e.g., balance, studentName).
Modularity
Designing a class to perform one clear purpose, improving code organization and reusability
Data Hiding
Keeping fields private so external code cannot modify them directly, enforcing encapsulation.
Validation in Setters
Adding checks in setter methods to prevent invalid data from being stored in fields
Class Composition Example
A Car class that includes an Engine object to represent its internal mechanism
Common Class Design Mistake
Forgetting to initialize fields, misusing static variables, or neglecting access control
Best Practice in Class Design
Keep one class per file, use private fields, descriptive names, and clear comments.
Fully Encapsulated Class
A class where all fields are private and can only be accessed or modified through public methods.