Open Means Open Means

Objects and Classes

Introduction:-

In c language we can define our own datatypes using   structures. Therefore it is  possible to develop application oriented datatype. We can define data elements as members of structure in c. However c do not allow us to define functions as members of the structures.

To  implement object oriented programming  ,it is necessary to declare data members and associated functions together.

Therefore c do not support object oriented programming.

In c++ it is possible to define data as well as functions as members of the structure or members of the class.

Therefore c++ supports oject oriented programming.

Class:- is nothing but a datatype that defines set of objects having identical characteristics.

The class definition is often made up of data  members and members functions.

Object:- The object is nothing but the physical existence of the class.

The object is also called as instance.

Consider the following eg:-

Class music-system

{

float length, breadth, depth;

float cost;

char color;

int no_of_speakers;

Public:

Void playcas ( );

void played cd ( );

void forward ( );

void rewind ( );

void record ( );

};

 

Music_system m1, m2;

→      In the above eg we have defined a class called music system which has got data members length, breadth, cost, color, depth, no of speakers.

→      The class have got following member function playcas, played, forward, rewind, record.

→      The m1 and m2 are defined as objects o6 class music system.

→      The members of the class will be accessed for the object as follows object name, member name.

No comments

Login to post a comment

Show
  • Create an account
  • Forgot your username?
  • Forgot your password?
  • About Us
  • Faqs
  • Contact Us
  • Disclaimer
  • Terms & Conditions