Easy Begginer Question (final static)

  • 18 years ago

    HI,
    I gotta write a console java program to accept a value from the user (pints)
    and convert it to litres, then output the answer,,


    and i just wanted to know,


    what is the diference between static and final ??


    WHEN i declaire a


    Double Pints = 0;


    in the main class (so that it is global)


    WHY will it not let me use the variable in the public static main ? unless i declaire it as a
    static double Pints ?????


    what does the static mean ?

  • 18 years ago


    final means that a variable or field can't be changed, a method can't be overriden
    and a class can't be subclasses, when final is used as a modifier in those
    situations.


    static means that a
    inner class is not associated with containing class,
    method is invoked with class name (instance not required)
    field/global variable - only one instance of field/variable no matter
    how many instances of the class are made. accessed with class name.


    That was taken almost word for word from Java in a Nutshell, my
    favorite book.


    Hope that helps,


    - Mike H


Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry