Fundamentals of OOP
Class
Object
Encapsulation
Abstraction
Inheritance
Polymorphism
Reusability
C++ as an OOP language
C++ : C with classes
Multi-paradigm language
As Object oriented language, it offers bottom to top approach
As Procedural language, it offers top to bottom approach
Classes and objects (I)
Class- user defined data type. Fundamental packaging unit of
OOP technology
Class declaration is similar to struct declaration
Keyword ‘class’ followed by class name.
Object is an instance of class
Object combines data and functions
Object is created as a variable of class type using class name
Members of class
Data members / attributes
Member functions / methods
Classes and objects (II)
Structure of C++ program with class
Data members
Data members can be any of the following types
Primary data types : int, float, char, double, bool
Secondary data types : arrays, pointers, class objects etc.
Data members classified into two groups
Regular : every object gets its own copy of data members
Static: all objects share the same copy of data memberStatic Data Members
Variable declaration preceded by keyword ‘static’
Only one copy of static variable is created. All the objects share the same
copy
Initialized to zero when first object is created. No other initialization
permitted.
Should be defined outside the class definition after declaring them
inside the class in this way – datatype classname :: varname
They are normally used to maintain values that are common to the
entire class, e.g., to keep a count of number of objects created.
Methods (I)
Function defined inside a class declaration is called as
member function or method
Methods can be defined in two ways - inside the class or
outside the class using scope resolution operator (::)
When defined outside class declaration, function needs to be
declared inside the class
Methods (II)
Method defined inside the
class
Method defined outside
the class
Methods (III)
Types of functions in a class
Regular functions
Overloaded functions
Inline functions
Friend functions
Static functions
Constructors
Destructors
Virtual functions
Class
Object
Encapsulation
Abstraction
Inheritance
Polymorphism
Reusability
C++ as an OOP language
C++ : C with classes
Multi-paradigm language
As Object oriented language, it offers bottom to top approach
As Procedural language, it offers top to bottom approach
Classes and objects (I)
Class- user defined data type. Fundamental packaging unit of
OOP technology
Class declaration is similar to struct declaration
Keyword ‘class’ followed by class name.
Object is an instance of class
Object combines data and functions
Object is created as a variable of class type using class name
Members of class
Data members / attributes
Member functions / methods
Classes and objects (II)
Structure of C++ program with class
Data members
Data members can be any of the following types
Primary data types : int, float, char, double, bool
Secondary data types : arrays, pointers, class objects etc.
Data members classified into two groups
Regular : every object gets its own copy of data members
Static: all objects share the same copy of data memberStatic Data Members
Variable declaration preceded by keyword ‘static’
Only one copy of static variable is created. All the objects share the same
copy
Initialized to zero when first object is created. No other initialization
permitted.
Should be defined outside the class definition after declaring them
inside the class in this way – datatype classname :: varname
They are normally used to maintain values that are common to the
entire class, e.g., to keep a count of number of objects created.
Methods (I)
Function defined inside a class declaration is called as
member function or method
Methods can be defined in two ways - inside the class or
outside the class using scope resolution operator (::)
When defined outside class declaration, function needs to be
declared inside the class
Methods (II)
Method defined inside the
class
Method defined outside
the class
Methods (III)
Types of functions in a class
Regular functions
Overloaded functions
Inline functions
Friend functions
Static functions
Constructors
Destructors
Virtual functions
intro to c++,need and applications
Reviewed by Shobhit Goel
on
May 05, 2015
Rating:
No comments:
Post a Comment