Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/variables/modifiers.md
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 |
Copy link
Collaborator

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.

| static | Belongs to the class rather than the object |
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 |
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is actually a default keyword for interfaces so thats a little confusing


### 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`
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The 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