-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c24e9c
commit c46baa2
Showing
20 changed files
with
1,320 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
class Human { | ||
public: | ||
int height; | ||
int weight; | ||
int age; | ||
}; | ||
|
||
class Male : public Human { | ||
|
||
}; | ||
|
||
class Female : protected Human { | ||
|
||
}; | ||
|
||
int main() { | ||
Male m; | ||
|
||
cout << "m.height : " << m.height << endl; | ||
cout << "m.weight : " << m.weight << endl; | ||
cout << "m.age : " << m.age << endl; | ||
|
||
Female f; | ||
// Not possible | ||
// cout << "f.height : " << f.height << endl; | ||
// cout << "f.weight : " << f.weight << endl; | ||
// cout << "f.age : " << f.age << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
class A { | ||
public: | ||
int base_property1; | ||
int base_property2; | ||
}; | ||
|
||
class B : public A { | ||
public: | ||
int child_property1; | ||
int child_property2; | ||
}; | ||
|
||
int main() { | ||
B b1; | ||
|
||
b1.base_property1 = 10; | ||
b1.base_property2 = 15; | ||
b1.child_property1 = 20; | ||
b1.child_property2 = 25; | ||
|
||
cout << "b1.base_property1 : " << b1.base_property1 << endl; | ||
cout << "b1.base_property2 : " << b1.base_property2 << endl; | ||
cout << "b1.child_property1 : " << b1.child_property1 << endl; | ||
cout << "b1.child_property2 : " << b1.child_property2 << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
class A { | ||
public: | ||
int base_property1; | ||
int base_property2; | ||
}; | ||
|
||
class B : public A { | ||
public: | ||
int child_property1; | ||
int child_property2; | ||
}; | ||
|
||
class C : public B { | ||
public: | ||
int new_child_property1; | ||
int new_child_property2; | ||
}; | ||
|
||
int main() { | ||
C c1; | ||
|
||
c1.base_property1 = 10; | ||
c1.base_property2 = 15; | ||
c1.child_property1 = 20; | ||
c1.child_property2 = 25; | ||
c1.new_child_property1 = 30; | ||
c1.new_child_property2 = 35; | ||
|
||
cout << "c1.base_property1 : " << c1.base_property1 << endl; | ||
cout << "c1.base_property2 : " << c1.base_property2 << endl << endl; | ||
cout << "c1.child_property1 : " << c1.child_property1 << endl; | ||
cout << "c1.child_property2 : " << c1.child_property2 << endl << endl; | ||
cout << "c1.new_child_property1 : " << c1.new_child_property1 << endl; | ||
cout << "c1.new_child_property2 : " << c1.new_child_property2 << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
class A { | ||
public: | ||
int base1_property1; | ||
int base1_property2; | ||
}; | ||
|
||
class B { | ||
public: | ||
int base2_property1; | ||
int base2_property2; | ||
}; | ||
|
||
class C : public A, public B { | ||
public: | ||
int child_property1; | ||
int child_property2; | ||
}; | ||
|
||
int main() { | ||
C c1; | ||
|
||
c1.base1_property1 = 10; | ||
c1.base1_property2 = 15; | ||
c1.base2_property1 = 20; | ||
c1.base2_property2 = 25; | ||
c1.child_property1 = 30; | ||
c1.child_property2 = 35; | ||
|
||
cout << "c1.base1_property1 : " << c1.base1_property1 << endl; | ||
cout << "c1.base1_property2 : " << c1.base1_property2 << endl << endl; | ||
cout << "c1.base2_property1 : " << c1.base2_property1 << endl; | ||
cout << "c1.base2_property2 : " << c1.base2_property2 << endl << endl; | ||
cout << "c1.child_property1 : " << c1.child_property1 << endl; | ||
cout << "c1.child_property2 : " << c1.child_property2 << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
class A { | ||
public: | ||
int base_property1; | ||
int base_property2; | ||
}; | ||
|
||
class B : public A { | ||
public: | ||
int child1_property1; | ||
int child1_property2; | ||
}; | ||
|
||
class C : public A { | ||
public: | ||
int child2_property1; | ||
int child2_property2; | ||
}; | ||
|
||
class D : public B, public C { | ||
public: | ||
int new_child_property1; | ||
int new_child_property2; | ||
}; | ||
|
||
int main() { | ||
D d1; | ||
|
||
// d1.base_property1 = 50; | ||
// d1.base_property2 = 55; | ||
d1.child1_property1 = 60; | ||
d1.child1_property2 = 65; | ||
d1.child2_property1 = 70; | ||
d1.child2_property2 = 75; | ||
d1.new_child_property1 = 80; | ||
d1.new_child_property2 = 85; | ||
|
||
// cout << "d1.base_property1 : " << d1.base_property1 << endl; | ||
// cout << "d1.base_property2 : " << d1.base_property2 << endl << endl; | ||
cout << "d1.child1_property1 : " << d1.child1_property1 << endl; | ||
cout << "d1.child1_property2 : " << d1.child1_property2 << endl << endl; | ||
cout << "d1.child2_property1 : " << d1.child2_property1 << endl; | ||
cout << "d1.child2_property2 : " << d1.child2_property2 << endl << endl; | ||
cout << "d1.new_child_property1 : " << d1.new_child_property1 << endl; | ||
cout << "d1.new_child_property2 : " << d1.new_child_property2 << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
class A { | ||
public: | ||
int base_property1; | ||
int base_property2; | ||
}; | ||
|
||
class B : public A { | ||
public: | ||
int child1_property1; | ||
int child1_property2; | ||
}; | ||
|
||
class C : public A { | ||
public: | ||
int child2_property1; | ||
int child2_property2; | ||
}; | ||
|
||
int main() { | ||
B b1; | ||
C c1; | ||
|
||
b1.base_property1 = 50; | ||
b1.base_property2 = 55; | ||
b1.child1_property1 = 60; | ||
b1.child1_property2 = 65; | ||
|
||
c1.base_property1 = 10; | ||
c1.base_property2 = 15; | ||
c1.child2_property1 = 20; | ||
c1.child2_property2 = 25; | ||
|
||
cout << "b1.base_property1 : " << b1.base_property1 << endl; | ||
cout << "b1.base_property2 : " << b1.base_property2 << endl << endl; | ||
cout << "b1.child1_property1 : " << b1.child1_property1 << endl; | ||
cout << "b1.child1_property2 : " << b1.child1_property2 << endl << endl; | ||
|
||
cout << "c1.base_property1 : " << c1.base_property1 << endl; | ||
cout << "c1.base_property2 : " << c1.base_property2 << endl << endl; | ||
cout << "c1.child2_property1 : " << c1.child2_property1 << endl; | ||
cout << "c1.child2_property2 : " << c1.child2_property2 << endl << endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
class A { | ||
public: | ||
int base_property1; | ||
int base_property2; | ||
}; | ||
|
||
class B : public A { | ||
public: | ||
int child1_property1; | ||
int child1_property2; | ||
}; | ||
|
||
class C : public A { | ||
public: | ||
int child2_property1; | ||
int child2_property2; | ||
}; | ||
|
||
class D : public B, public C { | ||
public: | ||
int new_child_property1; | ||
int new_child_property2; | ||
}; | ||
|
||
int main() { | ||
D d1; | ||
|
||
d1.B::base_property1 = 50; | ||
d1.B::base_property2 = 55; | ||
d1.C::base_property1 = 60; | ||
d1.C::base_property2 = 65; | ||
d1.child1_property1 = 70; | ||
d1.child1_property2 = 75; | ||
d1.child2_property1 = 80; | ||
d1.child2_property2 = 85; | ||
d1.new_child_property1 = 90; | ||
d1.new_child_property2 = 95; | ||
|
||
cout << "d1.B::base_property1 : " << d1.B::base_property1 << endl; | ||
cout << "d1.B::base_property2 : " << d1.B::base_property2 << endl << endl; | ||
cout << "d1.C::base_property1 : " << d1.C::base_property1 << endl; | ||
cout << "d1.C::base_property2 : " << d1.C::base_property2 << endl << endl; | ||
cout << "d1.child1_propertn y1 : " << d1.child1_property1 << endl; | ||
cout << "d1.child1_property2 : " << d1.child1_property2 << endl << endl; | ||
cout << "d1.child2_property1 : " << d1.child2_property1 << endl; | ||
cout << "d1.child2_property2 : " << d1.child2_property2 << endl << endl; | ||
cout << "d1.new_child_property1 : " << d1.new_child_property1 << endl; | ||
cout << "d1.new_child_property2 : " << d1.new_child_property2 << endl; | ||
|
||
return 0; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
class A { | ||
public: | ||
int a, b; | ||
|
||
int add() { | ||
return a+b; | ||
} | ||
|
||
void operator + (A &obj) { | ||
int value1 = this->a; | ||
int value2 = obj.a; | ||
cout << "Output : " << value2 - value1 << endl; | ||
} | ||
|
||
void operator () () { | ||
cout << "Bracket is called by " << this->a << endl; | ||
} | ||
}; | ||
|
||
int main() { | ||
A obj1, obj2; | ||
|
||
obj1.a = 2; | ||
obj2.a = 7; | ||
|
||
obj1 + obj2; | ||
|
||
obj1(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
class A { | ||
public: | ||
void func() { | ||
cout << "Inside Parent Class" << endl; | ||
} | ||
}; | ||
|
||
class B : public A { | ||
public: | ||
void func() { | ||
cout << "Inside Child Class" << endl; | ||
} | ||
}; | ||
|
||
int main() { | ||
A obj1; | ||
B obj2; | ||
|
||
obj1.func(); | ||
obj2.func(); | ||
|
||
return 0; | ||
} |
Empty file.
Oops, something went wrong.