Basics

8.1 Introduction to OOP:

8.2 Classes and Objects:

car.java file

public class CarRunner {

	public static void main(String[] args) {
		// Creating objects
		Car car1 = new Car();
		Car car2 = new Car();

		// Accessing properties and invoking methods
		car1.color = "Red";
		car1.year = 2020;
		car1.startEngine(); // Output: "Engine started!"

		car2.color = "Blue";
		car2.year = 2018;
		car2.stopEngine(); // Output: "Engine stopped!"
	}
}

CarRunner.java file

public class CarRunner {

	public static void main(String[] args) {
		// Creating objects
		Car car1 = new Car();
		Car car2 = new Car();

		// Accessing properties and invoking methods
		car1.color = "Red";
		car1.year = 2020;
		car1.startEngine(); // Output: "Engine started!"

		car2.color = "Blue";
		car2.year = 2018;
		car2.stopEngine(); // Output: "Engine stopped!"
	}
}

8.3 Encapsulation and Data Hiding: