Skip to content

Instantly share code, notes, and snippets.

@hakxcore
Created April 20, 2022 19:54
Show Gist options
  • Save hakxcore/4be1929583fd051e48c2f0f9b85aea8f to your computer and use it in GitHub Desktop.
Save hakxcore/4be1929583fd051e48c2f0f9b85aea8f to your computer and use it in GitHub Desktop.
## OBJECT ORIENTED PROGRAMMING
--|- Object Oriented Programming
|
1 |---- class
|
2 |---- object
|
3 |---- Abstraction
|
4 |---- Encapsulation
|
5 |---- Polymorphism
|
6 |---- Inheritence
1. Class: A class is a user defined datatype, Which holds its own datamembers and member functions. Class is like blueprint of an object.
# Syntax
`
Class person(){
char name[50];
int id;
public:
void printData(){
cout<<"Name: "<<name;
cout<<"ID: "<<id;
}
}
`
# C++ Code
`
#include <bits/stdc++.h>
using namespace std;
class Geeks
{
public:
string geekname;
void printname()
{
cout << "Geekname is: " << geekname;
}
};
int main() {
Geeks obj1;
obj1.geekname = "Abhi";
obj1.printname();
return 0;
}
`
2. Object: Object is an identifiable entity with some characterstics and behavious. An object is an instance of class.
# Syntax
`
person p1;
^ ^
| |
class object
`
3. Abstraction: Abstraction means displaying only essential information and hiding the details.
Data abstraction refers to providing only essential information about the data to the outside world, hiding the background details or implementation.
- Abstraction using Classes
- Abstraction in Header files
4. Encapsulation: Encapsulation is defined as wrapping up of data and information under a single unit.
In Object-Oriented Programming, Encapsulation is defined as binding together the data and the functions that manipulate them.
Encapsulation also leads to data abstraction or hiding.
5.--|-Polymorphism: The word polymorphism means having many forms.
|
1--|---- Compile Time Polymorphism.
|
2--|---- Run-time Polymorphism.
i) Compile time Polymorphism: The overloaded functions are invoked by matching the type and number of arguments. This information is available at the compile time and, therefore, compiler selects the appropriate function at the compile time. It is achieved by function overloading and operator overloading which is also known as static binding or early binding.
ii) Run-time Polymorphism: Run time polymorphism is achieved when the object's method is invoked at the run time instead of compile time. It is achieved by method overriding which is also known as dynamic binding or late binding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment