+ Reply to Thread
Results 1 to 4 of 4

Thread: static methods

  1. #1
    Join Date
    Jul 2009

    static methods

    in java a static method can access only static data members but main() is a static method
    still it is accessing the instance data members by creating an object of other class.
    how can it be possible?"

    [url=http://www.adverse-mortgage-centre.co.uk/******-report.html]****** report[/url]
    [url=http://www.supercash*2*.com]pay advance[/url]

  2. #2
    Join Date
    Aug 2009
    You have to be a little more specific than that.
    What kind of data types are you using?
    Why do you have to use static methods?
    In theory, using static methods in a single class is just like using non-static methods, only you have one instance of them in the whole class.
    Last edited by gordo; 08-05-2009 at 06:21 AM.

  3. #3
    Join Date
    Aug 2009
    Recently many of you, after reading Guide to Testability, wrote to telling me there is nothing wrong with static methods. After all what can be easier to test than Math.abs()! And Math.abs() is static method! If abs() was on instance method, one would have to instantiate the object first, and that may prove to be a problem. (See how to think about the new operator, and class does real work)

    The basic issue with static methods is they are procedural code. I have no idea how to unit-test procedural code. Unit-testing assumes that I can instantiate a piece of my application in isolation. During the instantiation I wire the dependencies with mocks/friendlies which replace the real dependencies. With procedural programing there is nothing to “wire̶*; since there are no objects, the code and data are separate.
    Last edited by gordo; 08-20-2009 at 07:47 AM.

  4. #4
    arif222 Guest
    The Java construct for implementing functions is known as the static method. In this section, you will learn how to organize your programs by defining and using other static methods within them.

    Using and defining static methods.
    As you know from using Java's Math library, the use of static methods is easy to understand. For example, when you write Math.abs(a-b) in a program, the effect is as if you were to replace that code by the value that is computed by Java's Math.abs() method when presented with the value a-b. This usage is so intuitive that we have hardly needed to comment on it. If you think about what the computer has to do to create this effect, you will realize that it involves changing a program's flow of control.

    You can define static methods other than main() in a .java file, as illustrated in Newton.java. This implementation is better than our original implementation because it clearly separates the two primary tasks performed by the program: calculating the square root and interacting with the user. We examine it in detail so that you can think carefully about what a static method is and how it operates.
    [url=http://www.laurensilva.com]maternity nursing bras[/url]

+ Reply to Thread

Similar Threads

  1. Replies: 9
    Last Post: 08-06-2008, 10:05 AM
  2. keylogger methods
    By rome87 in forum Viruses and Trojans
    Replies: 5
    Last Post: 04-26-2007, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts