-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
first activity #4
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
Question: Difference between encapsulation and abstraction ? | ||
|
||
|
||
Answer: | ||
|
||
Encapsulation: | ||
Encapsulation is about bundling data (attributes) and methods (functions) together, and restricting access to certain parts of the object. This helps in hiding the internal details and providing a clean interface for interacting with the object. | ||
|
||
|
||
#include <iostream> | ||
using namespace std; | ||
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move it at the top of file |
||
|
||
class EncapsulationExample { | ||
private: | ||
// we declare a as private to hide it from outside | ||
int a; | ||
|
||
public: | ||
// set() function to set the value of a | ||
void set(int x) | ||
{ | ||
a = x; | ||
} | ||
|
||
// get() function to return the value of a | ||
int get() | ||
{ | ||
return a; | ||
} | ||
}; | ||
|
||
// main function | ||
int main() | ||
{ | ||
EncapsulationExample e1; | ||
|
||
e1.set(10); | ||
|
||
cout<<e1.get(); | ||
return 0; | ||
} | ||
|
||
|
||
The concept of abstraction only shows necessary information to the users. It reduces the complexity of the program by hiding the implementation complexities of programs. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use proper comment syntax |
||
|
||
|
||
class Sum { | ||
private: | ||
// private variables | ||
int a, b, c; | ||
public: | ||
void sum(int x, int y) | ||
{ | ||
a = x; | ||
b = y; | ||
c = a + b; | ||
cout<<"Sum of the two number is : "<<c<<endl; | ||
} | ||
}; | ||
int main() | ||
{ | ||
Sum s; | ||
s.sum(5, 4); | ||
return 0; | ||
} | ||
|
||
|
||
|
||
Comment on lines
+66
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unnecessary extra lines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use proper comment syntax