Lesson 7 of 10
Classes & Objects
A class is a blueprint for creating objects. It defines properties (fields) and behaviors (methods). An object is an instance of a class. Use the new keyword to create objects.
JAVA
public class Car {
String brand;
int year;
void drive() {
System.out.println("Driving " + brand);
}
public static void main(String[] args) {
Car myCar = new Car();
myCar.brand = "Toyota";
myCar.year = 2023;
myCar.drive();
}
}