static loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sujaiganesh
    New Member
    • Sep 2008
    • 5

    static loop

    if you use a static loop
    the contents in that loop are readed when object create that class
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    What is a 'static loop'?

    kind regards,

    Jos

    Comment

    • chaarmann
      Recognized Expert Contributor
      • Nov 2007
      • 785

      #3
      Originally posted by JosAH
      What is a 'static loop'?

      kind regards,

      Jos
      I guess he means a static class with a loop inside.
      I further guess that in that loop some data is read (from file or so).

      But what's the question/problem? He did not mention...

      Comment

      • sujaiganesh
        New Member
        • Sep 2008
        • 5

        #4
        Originally posted by JosAH
        What is a 'static loop'?

        kind regards,

        Jos
        Code:
        static
        {
          Sustem.out.println("sujaiganesh");
        }
        this loop is inside the class
        but it acts as a constructer
        Last edited by Nepomuk; Sep 18 '08, 09:09 AM. Reason: removed email address and added [CODE] tags

        Comment

        • Nepomuk
          Recognized Expert Specialist
          • Aug 2007
          • 3111

          #5
          Originally posted by sujaiganesh
          Code:
          static
          {
            Sustem.out.println("sujaiganesh");
          }
          this loop is inside the class
          but it acts as a constructer
          Well, actually this is what you call a static initializer block, not any kind of loop. For example, if you run the code [code=java]public class Test {
          public static void main(String[] args) {
          System.out.prin tln("I'm in the main method");
          }
          static
          {
          System.out.prin tln("I'm in the static block");
          }
          }[/code] You will get the output
          Code:
          I'm in the static block
          I'm in the main method
          It is not a constructor, as it doesn't wait for an object to be created. It is thought for initializing static variables, without having to call any method manually.

          Greetings,
          Nepomuk

          Comment

          Working...