Classes and Objects Fundamentals
Classes and Objects
Fundamental OOP concepts defining blueprint and instances.
Class Example
public class Car {
String brand;
int year;
public Car(String brand, int year) {
this.brand = brand;
this.year = year;
}
public void start() {
System.out.println(brand + " started");
}
}Key Points
- Class = blueprint, Object = instance.
thisrefers to current object.- Constructor has same name as class.
- Usage:
Car myCar = new Car("Toyota", 2023);.