class and object:
class:
- 1. a class is a way to bind data and associated function together.
- 2. it allows data and function to hidden if necessary for external use.
- 3. defining a class means creating a user defined data type that behaves as built in data.
- 4. once a class has been declared we can create any number of object belonging to that class.
syntax:
class class_name
{
private:
data member;
member function;
public:
data member;
member function;
}; //end of class
Generally data are placed in private section and function are placed in public section.
- 5. class contains both data and function . Data are called data member and function are called member function.
- 6. data and function are defined in private section are not accessible out of the class.
- 7. data and function placed in public section are only accessible from outside the class.
- 8. the word private is optional . the data in function of class by default private.
An object is an instance of a class.
For example, the Car class defines the model, brand, and mileage. Now, based on the definition, we can create objects like
Car suv;
Car sedan;
Car van;Here, suv, sedan, and van are objects of the Car class. Hence, the basic syntax for creating objects is:
Class_Name object_name;
No comments:
Post a Comment