- Understanding classes and objects
- Learning about constructors
- Understanding access modifiers
- Working with instance variables and methods
- Understanding encapsulation principles
- Class: Blueprint or template for creating objects
- Object: Instance of a class with state and behavior
- State: Data stored in instance variables
- Behavior: Actions performed by methods
- Special methods called when creating objects
- Same name as class, no return type
- Initialize object state
- Can be overloaded
- public: Accessible from anywhere
- private: Accessible only within the class
- protected: Accessible within package and subclasses
- default: Accessible only within package
- Bundling data and methods that operate on that data
- Data hiding through private access
- Controlled access through public methods
- ClassAndObject.java - Basic class and object creation
- Constructors.java - Constructor examples
- AccessModifiers.java - Access modifier demonstration
- Encapsulation.java - Encapsulation principles
- Compile:
javac ClassAndObject.java - Run:
java ClassAndObject
- Create a Student class with properties and methods
- Build a BankAccount class with deposit/withdraw methods
- Create a Rectangle class with area and perimeter methods
- Implement a Car class with various properties
- Naming: Class names start with capital letter
- Single Responsibility: Each class should have one purpose
- Encapsulation: Use private fields with public getters/setters
- Constructors: Always provide constructors for your classes
Next Day: Day 08 - Inheritance and Polymorphism