← Java Programming learning path
Java Programming · Module 5 of 10

Classes and objects

Model real things with classes (blueprints) and objects (instances).

📖 Key ideas

  1. A class defines fields (data) and methods (behaviour).
  2. new creates an object: Student s = new Student();
  3. A constructor runs when an object is created and sets initial values.
  4. this refers to the current object.
  5. Each object has its own copy of instance fields; static fields are shared.
💡 Real-life example: A class is a cookie cutter; objects are the cookies. Same shape, different toppings.
ClassBlueprint for objects
ObjectInstance created from a class
ConstructorInitialises a new object
thisThe current object