← Java Programming learning pathJava Programming · Module 5 of 10
Classes and objects
Model real things with classes (blueprints) and objects (instances).
📖 Key ideas
- A class defines fields (data) and methods (behaviour).
- new creates an object: Student s = new Student();
- A constructor runs when an object is created and sets initial values.
- this refers to the current object.
- 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