Wow, almost half way through my "Month of Java" and I am startying to struggle a bit. Not because I am not making progress, but because I don't want to bore you with the same old information, you have seen over and over again. The progress I am making with CodeGym is good but sometimes it is getting me to go over the same stuff, hoping to have me remember everything with repetition. It is getting me to sometimes break away from what I am currently learning on there though and taking a different track for my post on Steemit.
That leads me to todays topic. I thought it would be a good idea to go through Java variables in more detail today and go through their life span and precedence.
A variable declared in a method exists and is visible from the point it is declared to the end of the method.
A variable declared in a code block will exist until the end of the code block.
A methods parameters will exists everywhere in the method.
A variable in an object exists during the entire lifespace of the object that contains them and are visible by the access modifiers: public and private.
Static variables exist the whole time the program is running and is also controlled by access modifiers.
If You Didn't Remember What Access Modifiers Are
A public access modifier can be a set to a variable, method or class from anywhere in a program and this is the highest level of access with no limitations.
A private access modifier can be set for a variable or method from the class it is declared in. All other classes will not be able to see these variables or methods.
No modifier is considered to be marked as default. If a variable or method are not marked with a modifier they will be visible to all the classes in the package they are declared in and no others.
Ok, just a short post for the day, but hope it was still useful.