-
Notifications
You must be signed in to change notification settings - Fork 70
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
02b7f9d
commit 64c573c
Showing
1 changed file
with
65 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,65 @@ | ||
# 19CSE201 - Advanced Programming | ||
![](https://img.shields.io/badge/Batch-22CYS-lightgreen) ![](https://img.shields.io/badge/UG-blue) ![](https://img.shields.io/badge/Subject-AdP-blue) | ||
![](https://img.shields.io/badge/-HPOJ-brown) | ||
|
||
## Access Specifiers | ||
- Public | ||
- Protected | ||
- Private | ||
|
||
### C++ | ||
``` | ||
class AccessSpecifierExampleClass { | ||
public: | ||
// Public members are accessible from outside the class | ||
int publicVar; | ||
void publicMethod() { | ||
// Code for the public method | ||
} | ||
protected: | ||
// Protected members are accessible from within the class and its derived classes | ||
int protectedVar; | ||
void protectedMethod() { | ||
// Code for the protected method | ||
} | ||
private: | ||
// Private members are only accessible within the class | ||
int privateVar; | ||
void privateMethod() { | ||
// Code for the private method | ||
} | ||
}; | ||
``` | ||
|
||
### Python | ||
``` | ||
class AccessSpecifierExampleClass: | ||
def __init__(self): | ||
# Public attribute | ||
self.public_var = 0 | ||
# Protected attribute (convention using a single leading underscore) | ||
self._protected_var = 0 | ||
# Private attribute (convention using a double leading underscore) | ||
self.__private_var = 0 | ||
def public_method(self): | ||
# Code for the public method | ||
pass | ||
def _protected_method(self): | ||
# Code for the protected method | ||
pass | ||
def __private_method(self): | ||
# Code for the private method | ||
pass | ||
``` | ||
|
||
Note: __X__, are typically used for special methods or attributes. These are often referred to as "**dunder**" (double underscore) methods. |