I would request you to review my previous blog post for a basic understanding of Object Oriented Programming (To Read Click Me)
From the previous post, we will extend our Car example for better realistic understanding,
- Class Car contains attributes such as color, engine power, size, airbag
- Class Car contains methods such as drive, brake
Class example,
Class Car
{
String Color;
String Power;}
From the above example, we have declared a class named Car and attributes are Color and Power.
Creating an Object from the above class
Car carObject = new Car();
Now, you can create as many as the object you want depending on the need of the program. This is called reusability. The below example explains the same.
Car audi = new Car();
Car ferrari = new Car();