From the course: Oracle Java Foundations
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Static - Java Tutorial
From the course: Oracle Java Foundations
Static
(gentle music) (transition whooshing) - [Joe] Static methods and variables. There's a modifier in Java called static that can be applied to a method or a variable. Using the static modifier means that the method or variable belongs to the class and is shared by all objects of that class. It is not specific to any object instance. For example, in the Clothing class, if we have a minimum price, that is the price for any piece of clothing can't be be below that, that would be a good candidate for a static variable because it's true across all object instances. It doesn't make sense to have each object instance have its own minimum price, which is going to be the same across all of them. Now this is a subtlety in design that can be a little bit difficult to grasp, but hang in there with us. These static methods and variables can be accessed without using new. You don't have to instantiate an object to access those variables or methods. So the class acts as a kind of single point of…