Data recovery software tools & file recovery utilities to recover lost data

WestNIC provides reliable web hosting services

Site navigation below

This answer is part of the Code Style premium content package. You must have a premium content subscription to log in and view the full answer to this question. Use the premium content subscription form below.

A: The static and final modifiers have quite distinct purposes in Java, though they can be used in combination to declare class constants. When the static modifier is applied to a variable or method it belongs to all instances of the class and can be referenced in a static context. In other words, the class does not have to be instantiated before the variable can be read or the method called. That means that static variables must be assigned at compile time and static methods cannot reference instance variables or call instance methods.

The final modifier can be applied to a class definition or method to prevent extension or overriding respectively. This helps the compiler optimise byte code for the class. When the final modifier is declared on a variable it means that its initial assignment will not change during the execution of the code. Final instance variables must be assigned at compile time or in the class' constructor, as in the example below.

Premium Content: Follow this link for subscription information More details available to premium content service subscribers:
What is the difference between static and final keywords?

Premium content subscription

You must make a subscription payment to access areas flagged premium content. Use the form below to create an account via PayPal.

Premium Content subscription @ $20.00 (USD) per year

Subscribe now:

Your security

The PayPal service allows you to pay securely and independently in your own currency. Payments are billed to Metacentric Internet Limited. We never handle your credit card details.

Why pay for premium content?

The Code Style site has accumulated 8 years' worth of answers to the most common Web development questions. Answers are written in clear English with examples and links to other Web resources. Your subscription provides full answers to all premium content questions listed below and other FAQ sections, plus:

Java programming FAQ: premium questions

Java language FAQ: premium questions

Java compiler FAQ: premium questions

Java command line FAQ: premium questions

Java objects FAQ: premium questions

Java inheritance FAQ: premium questions

Java abstract classes FAQ: premium questions

Java interface design FAQ: premium questions

Java API FAQ: premium questions

Java strings FAQ: premium questions

Java utility classes FAQ: premium questions

Java I/O FAQ: premium questions

JDBC FAQ: premium questions

Java threads FAQ: premium questions

Java servlets FAQ: premium questions

Servlet containers FAQ: premium questions

Add this page to your chosen social bookmarking service

Style warning - please read

Home · CSS · Java · Javascript · HTML · Help · Log