Read full document


By | August 2011
Page 1 of 7
Object oriented programming concepts:
Message Passing
Any thing that exists in the real world is called an object. Ex: pc,car,chair etc..
Any object will have properties and actions.

//object example
public class CreateObjectDemo {
public static void main(String[] args) {
Bicycle b =new Bicycle(10,20,30);

A class is a group name to which the objects having same behavior belong to. A class is a specification of properties and actions of objects. Ex: house plan is a class and house is an object.

An object does not exist without a class but a class can exists without any object

//class example
public class Bicycle {
// the Bicycle class has three fields
Public int cadence;
Public int gear;
Public int speed;
// the Bicycle class has one constructor
public Bicycle(intstartCadence, intstartSpeed, intstartGear) { gear = startGear;
cadence = startCadence;
speed = startSpeed;
// the Bicycle class has four methods
public void setCadence(intnewValue) {
cadence = newValue;
public void setGear(intnewValue) {
gear = newValue;
public void applyBrake(int decrement) {
speed -= decrement;
public void speedUp(int increment) {
speed += increment;
Taking variables and methods as a single unit is called encapsulation. Encapsulation is a protective mechanism, it isolates the members of one class from the members of another class. So, we can use same name in two different classes.

Hiding unnecessary data from the user is called abstraction. By using private, public etc access specifiers we can provide abstraction for the members of the class. Inheritance
Producing new classes from existing classes is called inheritance. Without rewriting the code we can reuse the code....

Rate this document

What do you think about the quality of this document?

Share this document

Let your classmates know about this document and more at