class and object in c++ by pawan thakur

Download Class and object in C++ By Pawan Thakur

Post on 19-Aug-2014

69 views

Category:

Education

15 download

Embed Size (px)

DESCRIPTION

Classes extend the built-in capabilities of C++ able you in representing and solving complex, real-world problems. A class is an organization of data and functions which operate on them. Data structures are called data members and the functions are called member functions, the combination of data members and member functions constitute a data object or simply an object. Class is a group of data member and member functions. Another word class is a collection of objects of similar type. To create a class, use the class keyword followed by a name for the object. Like any other declared variable, the class declaration ends with a semi-colon. The name of a class follows the rules we have applied for variable and function names.

TRANSCRIPT

  • 7.1. INTRODUCTION Classesextendthebuilt-incapabilitiesofC++ableyouinrepresentingandsolvingcomplex, real-world problems. A class is an organization of data and functions which operate on them. Data structures are called data members and the functions are called member functions, the combination of data members and member functions constitute a data object or simply an object. Class is a group of data member and member functions. Another word class is a collection of objects of similar type. To create a class, use the class keyword followed by a name for the object. Like any other declared variable, the class declaration ends with a semi-colon. The name of a class follows the rules we have applied for variable and function names. To declare a class you would type the following: syntax: class class_name { access_specifier_1: shift hight one tab ------------------- ---------------------data member and member functions LEARNING OBJECTIVES At the end of this chapter you will be able to understand : Concepts of Classes Objects Construction and Destructor Overloading Inheritence L
  • 7-2 CLASSES AND OBJECTS . access_specifier_2: ------------------- ---------------------data member and member functions . } ; Where class_name is a valid identifier for the class. The body of the declaration can contain members, that can be either data or function declarations, or optionally access specifiers.All is very similar to the declaration on data structures, except that we can now include also functions and members, but also this new thing called access specifier. An access specifier is one of the following three keywords: private, public or protected. These specifiers modify the access rights that the members following them acquire: (a) Private members-: Private members of a class are accessible only from within other members of the same class or from their friends. (b) Protected members-: Protected members are accessible from members of their same class and from their friends, but also from members of their derived classes. (c) Public members-: Public members are accessible from anywhere where the object is visible. By default, all members of a class declared with the class keyword have private access for all its members. Therefore, any member that is declared before one other class specifier automatically has private access. The program 7.1 demonstrates the concept of class. Example 7.1.Aclass Example class demo { int x,y,z; public: void getxy() { coutx; couty; } void getsum() { z=x+y; cout