19-06-2012, 01:20 PM
CLASSES AND OBJECTS
OBJECT AND CLASSES..pptx (Size: 237.72 KB / Downloads: 17)
Class
A class is a self-contained entity that stores its own data and its own functions.
It is an extension of structure of C.
It is a derived data type like an array. But unlike an array whose elements are all of the same type, elements of a class may have different data type.
Variables and function declared inside a class are known as members of that class.
A class is defined using keyword class.
Difference between structures and classes
C does not allow structure data type to be treated like a built in type. Example: if C1,C2 and C3 are the 3 structure variables then the statements like C3=C1+C2 is illegal. Similarly “=“ operator cannot be applied on two structure variables like C1=C2
Structures do not permit data hiding. That means members of the structures can be accessed by structure variables by any function anywhere in their scope. By default structure members are public in nature.
Class function definition
Here is an example of the class with two private data a and b of int type. Read() and display are the two public member functions.
Creating Objects
Once the class has been declared we can create variables of that type by using the class name. Class variables are known as objects.
Example: data D1,D2