Introduction to
Object Oriented
Programming
What is (OOP)?
OOP stands for
Object-Oriented Programming. Object-oriented
programming is about creating objects that contain both data and functions.
Object-oriented
programming has several advantages over procedural programming:
- OOP
is faster and easier to execute.
- OOP
provides a clear structure for the programs.
- OOP
helps to keep the C++ code DRY "Don't Repeat Yourself", and makes the
code easier to maintain, modify and debug
- OOP
makes it possible to create full reusable applications with less code and
shorter development time.
Basic Concepts in Object-Oriented Programming
- Classes -- Basic template for creating
objects
- Objects – Basic
run-time entities
- Data Abstraction & Encapsulation
– Wrapping data and functions into a single unit
- Inheritance
– Properties of one class can be inherited into others
- Polymorphism
– Ability to take more than one forms
Object-Oriented Programming Topics:
Object -- an encapsulation of data
along with functions that act upon that data.
An object consists of:
- Name -- the variable name we
give it
- Member data --
the data that describes the object
- Member functions --
behavior aspects of the object
Class -- a blueprint for objects. A
class is a user-defined type that describes what a certain type of object will
look like. A class description consists of a declaration and a definition.
Usually these pieces are split into separate files.
Class syntax
Defination:
Create a Class
• To create a class, use the class keyword:
• Create a class called "MyClass":
Create a Object
·
In C++, an object is created from a class. We
have already created the class named MyClass, so now we can use this to
create objects.
- To create an object of MyClass, specify
the class name,
followed by the object name.
- To access the class attributes
(myNum and myString), use the dot syntax (.) on the object:
C++ Class
Methods
There
are two ways to define functions that belongs to a class:
- •
Inside class definition
- •
Outside class
definition
InSide Class
Outside Class
0 Comments
Thanks for Supporting me