0% found this document useful (0 votes)
3 views

OOP Notes (cpp)

Object-oriented programming (OOP) in C++ utilizes classes and objects to enhance code organization, reusability, and maintainability. Key concepts include encapsulation, inheritance, polymorphism, and abstraction, which help in modeling real-world scenarios and managing complex systems. OOP allows developers to create blueprints for objects, enabling efficient memory management and code reuse through constructors and destructors.

Uploaded by

prakharsachan110
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

OOP Notes (cpp)

Object-oriented programming (OOP) in C++ utilizes classes and objects to enhance code organization, reusability, and maintainability. Key concepts include encapsulation, inheritance, polymorphism, and abstraction, which help in modeling real-world scenarios and managing complex systems. OOP allows developers to create blueprints for objects, enabling efficient memory management and code reuse through constructors and destructors.

Uploaded by

prakharsachan110
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

opps

------

what is opps important and why it is used


-------------------------------------------------
vectors , strings , stack etc library of c++ exsists in STL because of opps
to implement this we use opps concept internally

Object-oriented programming (OOP) is a programming model that uses classes and


objects to design programs in C++

it is another way of writing code , if we use opps to implement logic rather than
using
simple c++ it makes easier to implement real life and practical senerios in our
code

why important
-------------

a way of thinking about and organizing code for maximum reusability

it helps to improve code organization and maintainability, and can save time by
allowing developers to reuse code

if more explain Toyota example

--------------------------------

method - is a function written inside the class or functions which are made for
classes and objects are methods

just make class one time - and use that again and again to make objects - that why
opps increases reusability
ex - teachers example is important
like give blue print one time toyate will use that to manufacture the different car
again n again using that one blueprint(classes)\

also in teacher(object) ex - only one we have to say what are its properties and
methods and then we can create may teachers profile together instead of creating
lots of variables
so if we have to use entites which are close to real world and it has many
properties and method , there will use classes and objects

strings
--------
A string is a variable that stores a sequence of letters or other characters, such
as "Hello" or "May 10th is my birthday!
-----------------------------------------------------------------------------------
------

by default everthing is private in c++ - attributes(properties) , member function

setter function - to set the private values


getter function - to get the values of privates properties
Encapsulation
-----------------
- Data hiding - hiding imp or sensitive info
we are doing this through access specifier - private:(keeping imp info in privte
and not giving access)

constrctor
----------
if we want that one value of data member/attribute is set and its doesn't change we
can use constructor
like in teacher , we can use dep = computer , so everytime objected is created ,
automatically dept will be computer
we don't have to write t1.dept = "computer";

--> allocates memory

memory allocation is for objects when they are created not for classes , when call
is going to constructor

types of constructor:-
1 - non parameterized consss
2 - parameterized function
3 - copy constructor

constructor overloading - when there more than one constructor with same name , but
they have diff number of parameters
it is allowed

copy constructor is also by default called by compiler


wx - teacher t1(student name , dept) - object
techer t2 (t1) - 2nd object and it will copy the properties of first object

copy con - makes shallow copy not deep copy

but when we are doing dynamic memory allocation , the issue is coming in shwllow
copy

destructor
------------------
it is also automatically called by compiler
opp of constrctor

--> deallocates memory

it has same name as class name

~teacher(){
cout<<"i am deleting";
}

--> A destructor is a member function that is invoked automatically when the object
goes out of scope
use to destroye a object

Inheritance
-----------
It is used for code reusability
ex - let class A(parent class , base class) has one property , so why to make it
again for other classes
we will directly inherit to our class B(child , derived class)

companies has very big classes which has many properties , so to write code for
properties again and again it not suitable

--> if we have any private member or info in parent or base class it will never
inherits to the child class

let suppose we have private properties that we want to inherit , we dont want to
give access just want to inherit it
so we can make it protected;
so that it's derived class can also access those properties;

real life example


----------------------
A child inherits some properties from his/her parents, such as the ability to
speak, walk, eat, and so on

example, in a system for modeling animals, you can have a base class, Animal, and
derived classes like Dog, Cat, and Bird,

ex - let take example of bank , we can make account as parent class and then we can
make coustomer as a derived class and we can inherit the properties like name ,
id , password;

Polymorphism
-----------------
ex - constructor overloading

types:-
------
1 - compile time poly - means during compile time only we know the output
ex - constructor overloading
ex - function overloading - is an compile time poly , when we have function with
same name but have diff types or number of parameters
ex - operator overloading - same operator we are using in diff forms

2 - Run time - during run it will decide the output


ex - function overriding
-- if we are making child class object it will execute child class function and if
we are making parent class object it will execute parent class function

ex - virtual function
if we are writing virtual infront of any function it will become virtual function
any function can be made virtual function;

--> They are mainly used to achieve Runtime polymorphism.


The virtual function is the parent class function which we want to redefine in the
child class.

Abstraction
-------------
whenever we use access modifiers in our class that means we are using abstraction
also it not only hide sentive and uncessary info but also responsible for showing
important info also

Encapsulation - only hides the data . but Abstraction hides + shows the necceasary
info also

Abstraction - can also be implemented using abstract classes


abstract class teacher{

};
abstract class never creates any objects
it becomes the blueprint of other classes that are going to be implemented
it is only made for inheritance

You might also like