Skip to content

Latest commit

 

History

History

README.md

Day 07 - Object-Oriented Programming Basics

📚 What You'll Learn Today

  • Understanding classes and objects
  • Learning about constructors
  • Understanding access modifiers
  • Working with instance variables and methods
  • Understanding encapsulation principles

🎯 Key Concepts

Classes and Objects

  • 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

Constructors

  • Special methods called when creating objects
  • Same name as class, no return type
  • Initialize object state
  • Can be overloaded

Access Modifiers

  • public: Accessible from anywhere
  • private: Accessible only within the class
  • protected: Accessible within package and subclasses
  • default: Accessible only within package

Encapsulation

  • Bundling data and methods that operate on that data
  • Data hiding through private access
  • Controlled access through public methods

📁 Files in This Day

  1. ClassAndObject.java - Basic class and object creation
  2. Constructors.java - Constructor examples
  3. AccessModifiers.java - Access modifier demonstration
  4. Encapsulation.java - Encapsulation principles

🚀 How to Run

  1. Compile: javac ClassAndObject.java
  2. Run: java ClassAndObject

💡 Exercises

  1. Create a Student class with properties and methods
  2. Build a BankAccount class with deposit/withdraw methods
  3. Create a Rectangle class with area and perimeter methods
  4. Implement a Car class with various properties

🔍 Important Notes

  • 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

📖 Additional Resources


Next Day: Day 08 - Inheritance and Polymorphism