diff --git a/OOPS/accessspecifire.cpp b/OOPS/accessspecifire.cpp new file mode 100644 index 0000000..c364914 --- /dev/null +++ b/OOPS/accessspecifire.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +class myClass +{ +private: + int y = 10; // declared as inaccessible +public: + int x = 5; + myClass() // constructor having same name as the class + { + cout << "hello world!"; + } +}; +int main() +{ + myClass myObj; + cout << myObj.x; + // cout << myObj.y; + return 0; +} +/*cessspecifire.cpp:18:19: error: 'int myClass::y' is private within this context + cout << myObj.y; + ^ +accessspecifire.cpp:6:13: note: declared private here + int y = 10; // declared as inaccessible + ^~*/ \ No newline at end of file diff --git a/OOPS/accessspecifire.exe b/OOPS/accessspecifire.exe new file mode 100644 index 0000000..9a79113 Binary files /dev/null and b/OOPS/accessspecifire.exe differ diff --git a/OOPS/addconstructor.cpp b/OOPS/addconstructor.cpp new file mode 100644 index 0000000..6a2a576 --- /dev/null +++ b/OOPS/addconstructor.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; +class myAddition +{ +public: + myAddition(int x, int y) // constructor having same name as the class + { + cout << "Sum: " << x + y; + } +}; +int main() +{ + myAddition myObj(4, 5); + return 0; +} \ No newline at end of file diff --git a/OOPS/addconstructor.exe b/OOPS/addconstructor.exe new file mode 100644 index 0000000..be34961 Binary files /dev/null and b/OOPS/addconstructor.exe differ diff --git a/OOPS/class.cpp b/OOPS/class.cpp new file mode 100644 index 0000000..3b900e2 --- /dev/null +++ b/OOPS/class.cpp @@ -0,0 +1,14 @@ +/*Classes in Cpp*/ +#include +using namespace std; +class myClass +{ +public: + string s = "hello"; +}; +int main() +{ + myClass myObj; + cout << myObj.s; + return 0; +} \ No newline at end of file diff --git a/OOPS/class.exe b/OOPS/class.exe new file mode 100644 index 0000000..ded9ca4 Binary files /dev/null and b/OOPS/class.exe differ diff --git a/OOPS/classmethod2.cpp b/OOPS/classmethod2.cpp new file mode 100644 index 0000000..508fc66 --- /dev/null +++ b/OOPS/classmethod2.cpp @@ -0,0 +1,19 @@ +/*class methods inside class defination*/ +#include +using namespace std; +class myClass +{ +public: + void myMethod(); +}; +void myClass ::myMethod() +{ + cout << "hello world from outside the class!"; +} + +int main() +{ + myClass myObj; + myObj.myMethod(); + return 0; +} \ No newline at end of file diff --git a/OOPS/classmethod2.exe b/OOPS/classmethod2.exe new file mode 100644 index 0000000..04beac9 Binary files /dev/null and b/OOPS/classmethod2.exe differ diff --git a/OOPS/classmethods.cpp b/OOPS/classmethods.cpp new file mode 100644 index 0000000..7073736 --- /dev/null +++ b/OOPS/classmethods.cpp @@ -0,0 +1,17 @@ +/*class methods inside class defination*/ +#include +using namespace std; +class myClass +{ +public: + void myMethod() + { + cout << "hello world!"; + } +}; +int main() +{ + myClass myObj; + myObj.myMethod(); + return 0; +} \ No newline at end of file diff --git a/OOPS/classmethods.exe b/OOPS/classmethods.exe new file mode 100644 index 0000000..6d52db3 Binary files /dev/null and b/OOPS/classmethods.exe differ diff --git a/OOPS/constructor.cpp b/OOPS/constructor.cpp new file mode 100644 index 0000000..ab20e71 --- /dev/null +++ b/OOPS/constructor.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; +class myClass +{ +public: + myClass() // constructor having same name as the class + { + cout << "hello world, I am a constructor!"; + } +}; +int main() +{ + myClass myObj; // constructor call itself + + return 0; +} \ No newline at end of file diff --git a/OOPS/constructor.exe b/OOPS/constructor.exe new file mode 100644 index 0000000..8a9f166 Binary files /dev/null and b/OOPS/constructor.exe differ diff --git a/OOPS/encapsulation.cpp b/OOPS/encapsulation.cpp new file mode 100644 index 0000000..5479c61 --- /dev/null +++ b/OOPS/encapsulation.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; +class Employee +{ +private: + int salary; + // through encapsulation we can access private data members +public: + // setter method to set salaray + void setsalary(int s) + { + salary = s; + } + int getsalary() + { + return salary; + } +}; +int main() +{ + Employee empObj; + empObj.setsalary(50000); + cout << empObj.getsalary(); + return 0; +} \ No newline at end of file diff --git a/OOPS/encapsulation.exe b/OOPS/encapsulation.exe new file mode 100644 index 0000000..180fc1f Binary files /dev/null and b/OOPS/encapsulation.exe differ diff --git a/OOPS/polymorphism.cpp b/OOPS/polymorphism.cpp new file mode 100644 index 0000000..95bbe43 --- /dev/null +++ b/OOPS/polymorphism.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; +class Animal +{ +public: + void animalsound() + { + cout << "this animal makes sound...."; + } +}; +class Monkey : public Animal +{ +public: + void animalsound() + { + cout << "monkey makes sound...."; + } +}; +int main() +{ + Monkey myObj; + myObj.animalsound(); + myObj.Animal::animalsound(); // Call animalsound() from Animal class + return 0; +} \ No newline at end of file diff --git a/OOPS/polymorphism.exe b/OOPS/polymorphism.exe new file mode 100644 index 0000000..c250e55 Binary files /dev/null and b/OOPS/polymorphism.exe differ