Java: Modifiers
Quick summary
- static - not instantiated – belongs to the class not the object; any changes affect every instance.
- abstract - can’t be instantiated; can be extended only.
- final - can’t be subclassed or modified. (used with constants)
- void- returns nothing
- [default, concrete] - can be instantiated
Eclipse examples
- Eclipse example: static_fields_methods
- Eclipse example: final_fields_methods
- Eclipse example: final_class
- Eclipse example: abstract_classes_methods
See also topic Abstract methods.
See also Access modifiers.
Sponsored
Static
If your method is static, it cannot use instance variables that aren’t also static. Static stuff must all be static. Otherwise, you introduce change where it’s marked as non-changing.
Think of “stasis” – unchanging. No matter if you instantiate a class that has static members, the members don’t change.
The static keyword in Java means that the variable or function is shared between all instances of that class as it belongs to the type, not the actual objects themselves. So if you have a variable: private static int i = 0; and you increment it ( i++ ) in one instance, the change will be reflected in all instances. What does the ‘static’ keyword do in a class? Stack Overflow
Abstract
If you mark a class as abstract, it can’t be instantiated. Only concrete classes can be instantiated.
Final
From Stackoverflow.com
Final keyword has a numerous way to use:
- A final class cannot be subclassed.
- A final method cannot be overridden by subclasses
- A final variable can only be initialized once
Method overriding
Good resource: Java Method Overriding Examples and Concepts: Overriding Rules
About Tom Johnson
I'm an API technical writer based in the Seattle area. On this blog, I write about topics related to technical writing and communication — such as software documentation, API documentation, AI, information architecture, content strategy, writing processes, agent skills, tech comm careers, and more. Check out my AI courses for more on the latest in AI and tech comm. If you're looking for info about documenting APIs, see my API documentation course.
If you're a technical writer and want to keep on top of the latest trends in tech comm, be sure to subscribe to email updates below. You can also learn more about me or contact me.
Finally, I want to note a couple of things. I usually write the first drafts of my posts myself and then use AI to improve accuracy, clarity, and detail in places, so my writing is a mix of human and AI. (Hopefully that's not too off-putting.) Also, the opinions I express on my blog are my own perspectives, not those of my employer.