Understanding Static verses non static

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coppergarden
    New Member
    • Jun 2007
    • 1

    #1

    Understanding Static verses non static

    I am new to Java and while I have gotten a grasp on several things, I am still uncertain about static and what it means.

    I have a call I am needing to make to calculate a running total. I have this as my method:

    [PHP]public double addTotal(double value)
    {
    total = total + value;
    return total;
    //method to tally value
    }[/PHP]

    (not sure if I am using the tags correctly, please let me know if I am not.)

    and I have the call located in my main method

    [PHP]CD[i].addTotal(value );//call to tally[/PHP]

    While I am sure there is an easier way to do this, I am trying to get a grasp on the basics before I start using all the classes out there.

    Here is my question: How can you call a method from within the main method? I have read and it seems to have something to do with my variable, value.

    Thanks,

    d
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by coppergarden
    I am new to Java and while I have gotten a grasp on several things, I am still uncertain about static and what it means.

    I have a call I am needing to make to calculate a running total. I have this as my method:

    [PHP]public double addTotal(double value)
    {
    total = total + value;
    return total;
    //method to tally value
    }[/PHP]

    (not sure if I am using the tags correctly, please let me know if I am not.)

    and I have the call located in my main method

    [PHP]CD[i].addTotal(value );//call to tally[/PHP]

    While I am sure there is an easier way to do this, I am trying to get a grasp on the basics before I start using all the classes out there.

    Here is my question: How can you call a method from within the main method? I have read and it seems to have something to do with my variable, value.

    Thanks,

    d
    Well you are using the wrong code tags. Use the # symbol and add =java in [code] so it becomes [code=java] not the < > symbol (which gives php code tags).
    The static keyword is discussed here.

    Comment

    Working...