View RSS Feed

Java Object

What Is a Class?

Rate this Entry
by , 04-26-2012 at 05:31 PM (418 Views)
Various individual objects are present in real world which are of same kind. Hundreds or even thousands of bicycles might be present, of same model or make. Every bicycle was made by similar blueprints sets and hence consists of similar components. In terms of object-oriented, we shall say that bicycle is class of object’s instance, known as bicycle. Class is considered to be the blueprint which creates the individual objects.

One possible bicycle implementation of bicycle class is given below:
Java Code:
class Bicycle {

    int cadence = 0;
    int speed = 0;
    int gear = 1;

    void changeCadence(int newValue) {
         cadence = newValue;

    void changeGear(int newValue) {
         gear = newValue;

    void speedUp(int increment) {
         speed = speed + increment;   

    void applyBrakes(int decrement) {
         speed = speed - decrement;

    void printStates() {
         System.out.println("cadence:" +
             cadence + " speed:" + 
             speed + " gear:" + gear);
Java programming language’s syntax would be a newer thing for you; however this class’s design is based at the discussion that has been done at bicycle object. Fields speed, gear and cadence present the state of object and the methods (changeGear, changeCadence, speedUp etc.)Show the interaction that takeplace with outer world.

Submit "What Is a Class?" to Facebook Submit "What Is a Class?" to Digg Submit "What Is a Class?" to Submit "What Is a Class?" to StumbleUpon Submit "What Is a Class?" to Google