Tag Archives: Java class

Java Classes [Java]

In real life, we know that many objects are similar. For example, every car shares some similarities. We can use a basic blueprint and modify it to make other cars. A class in java is the blueprint you use to make objects. Here is an example:

class Car{

    int speed = 0
    int gear = 1;
    void changeGear(int value) {
         gear = value;
    }

    void speedUp(int amount) { 
         speed = speed + amount; 
    }

    void slowDown(int amount) {
         speed = speed - amount;
    }

    void printInfo() {
         System.out.println("Gear:" + gear + " Speed:" + speed);
    } 

}

In this we setup basic variables and created a few methods to change those variables.… View full post