Go to Top

Sunday 24 April 2011

What is the difference between objects and classes

Objects vs. Classes


  • An class is not the same as the object that is made from it. A class is just like the blueprint of the object, and the object is just like the product that is made by using the blueprint.For example, in a factory making cups, for a same type of cup, first a mould of the cup is made which defines the design, size, and shape of the cup. Here the mould is a blueprint which acts like a class, whereas the products i.e. the cups made by using the mould act like the objects. A class can be used to create any number of objects, such as a blueprint can be used to create any number of products or, a mould can be used to manufacture any number of cups as in the above example. 
  • An object will always occupy some memory space in the system's hard disk drive, but a class will not, because a class is merely a blueprint used to create the object whereas an object is the product made using the blueprint.
  • A class is just like a template from which an object is created.


Differences at at glance :-


1) Constituents :-

Class : Collection of variables and functions.

Object : Has access to the methods of the class, but not its data in the member variables.

2) Format :- 

Class : The format is given as follows : 

class <class name>
{
  functions.....
  variables.....
}

Object : The format is given as follows : 

class-name object-name=new class-name( );


Examples :-

  • Example 1 :-


Class : car_design 
Variables : speed, colour, size
Functions : accelerate, decelerate, stop

Object : car
Functions : accelerate, decelerate, stop

  • Example 2 :-


Class : laptop_design
Variables : processor frequency, hard disk, random access memory
Functions : switch on, switch off, calculate

Object : laptop
Functions : switch on, switch off, calculate

  • Example 3 :- 


Class : mobile_design
Variables : size, shape, processor frequency, features
Functions : call,  receive call, type a message

Object : mobile
Functions : call,  receive call, type a message

1 comment:

  1. ,sfjjjjjjjjjjjjjjj,wlllllllllllllllllejfkledknfwkldfv;skfnvkdfnvdnvku823040878843038i49859jginjbjitjibirmigmbi
    U wont understand(A program created by me).Professional coders in our institution could not decode it. An open invitation to decode it

    ReplyDelete

ShareThis