-
-
Notifications
You must be signed in to change notification settings - Fork 37
Create modifiers.md #41
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
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,35 @@ | ||
| ## Modifiers | ||
| ### Intro: | ||
|
|
||
| | Modifier | Description | | ||
| | --- | --- | | ||
| | public | Accessible from any other class | | ||
| | private | Accessible only within the class they are declared | | ||
| | protected | Accessible within the package and outside the package but through inheritance only | | ||
| | static | Belongs to the class rather than the object | | ||
|
Collaborator
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. Static methods are a much wider topic that deserves its own section(s) |
||
| | final | Value can't be changed | | ||
| | abstract | Can't be instantiated | | ||
| | synchronized | Threads handle the method or block of the method sequentially | | ||
|
Collaborator
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. Multi threading is not explained yet, at any level |
||
| | volatile | Value can be modified by different threads | | ||
| | default | No modifier specified, accessible within the same package | | ||
|
Collaborator
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. There is actually a |
||
|
|
||
| ### Explanation | ||
|
|
||
| `public`: You can access a variable/function from any package/class doesnt need to extend/impl | ||
|
|
||
| `protected`: It extends visibility to subclasses regardless of their package however it should extend/impl the class or it wont work | ||
|
|
||
| `default`: Its limited to the same package (you cant access it from sub-packages) | ||
|
|
||
| `private` : You can only access it from the same class | ||
|
|
||
| `static`: This means when you have an object (an instance of a class) the function/data is for the class not the object meaning if you run it 1000 times it wont change based on what the object gives. Its completely static to the class | ||
|
|
||
| `final`: Given to a variable given `API_KEY` wont change thus we will associate it with `final` | ||
|
Collaborator
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. This prose implies a familiarity with the private static final String API_KEY = "abc";pattern. Which none of the preceeding sections would have primed a reader for |
||
|
|
||
| `abstract`: Acts like a blueprint. Its good for making sure subclasses are pretty synchronized in the methods they have. Also you can share functions between subclasses instead of repeating them. `interface` **Acts the same** but it also assumes everything within it is also abstract. | ||
|
Collaborator
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. Interfaces are not explained yet |
||
|
|
||
| ### Differences between `abstract` and `interface` | ||
|
|
||
| - You can have multiple interfaces but only one abstract method | ||
| - Fields inside interfaces are both `static` and `final` So the same values apply to each object | ||
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.
Inheritance is not explained yet.