Skip to content

Commit

Permalink
Example for Access Specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
ramagururadhakrishnan authored Dec 24, 2023
1 parent 02b7f9d commit 64c573c
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Materials/Access_Specifiers.md
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.

0 comments on commit 64c573c

Please sign in to comment.