Classes
Classes are the basic outline of an obiect When programmmg With an object-based programming language you can easily over look all those concerns that are not directly related with th behaviour of an object or with the state of that object. This sug ge~ts that whIle programming we need to provide an outline of a object. We also need to keep in mind that the class does not stan for an. object. We can consider the class as something like an extensive type statement.
Let us go through an example of Class:
The following 'Car' class is one possible implementation of a car:
class Car
int tempo = 0;
int velocity = 0;
int gear = 1;
void changeTempo(int newValue)
tempo = newValue;
vpid changeGear(int newValue)
gear = newValue;
void velocityUp(int increment)
( velocity = velocity + increment;
void applyBrakes(int decrement) ( velocity = velocity - decrement;
void printStates() (
System.out.println("tempo:"+tempo+"
velocity:"+velocity+" gear:"+gear);
![]()



Reply With Quote
Bookmarks