xxxxxxxxxx
// Define a class named "Car"
class Car {
// Instance variables
String brand;
String model;
int year;
// Constructor to initialize the object
public Car(String brand, String model, int year) {
this.brand = brand;
this.model = model;
this.year = year;
}
// Instance method to display information about the car
public void displayInfo() {
System.out.println("Brand: " + brand);
System.out.println("Model: " + model);
System.out.println("Year: " + year);
}
}
public class ObjectExample {
public static void main(String[] args) {
// Create an object of the "Car" class
Car myCar = new Car("Toyota", "Camry", 2022);
// Access the properties and invoke methods using the object
myCar.displayInfo();
}
}