Difference between static and non-satic members in interface.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Difference between static and non-satic members in interface.

    Please can you help me to figure out the differences between static and non-static members in interfaces?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Only fields can be static in an interface (they're implicitly static, public and final). Methods
    are implicitly abstract and public.

    kind regards,

    Jos

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by JosAH
      Only fields can be static in an interface (they're implicitly static, public and final). Methods
      are implicitly abstract and public.

      kind regards,

      Jos
      Thanks that's what i expected .... so one more question ..what abut static and non-static inner interface?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by dmjpro
        Thanks that's what i expected .... so one more question ..what abut static and non-static inner interface?
        There's a new little article in this forum; it is at the top of the threads page and
        is named "Read This First". There's a link to the Java Language Specifiction in
        there; if I'm not mistaken it's chapter #9 that answers all your questions you
        were too afraid to ask.

        kind regards,

        Jos

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by JosAH
          There's a new little article in this forum; it is at the top of the threads page and
          is named "Read This First". There's a link to the Java Language Specifiction in
          there; if I'm not mistaken it's chapter #9 that answers all your questions you
          were too afraid to ask.

          kind regards,

          Jos
          Basically what happened Jos that yesterday i downloaded the PDF..
          But i think it would be difficult to understand if i don't understand Mathematics, that's why i left that book . :-)

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by dmjpro
            Basically what happened Jos that yesterday i downloaded the PDF..
            But i think it would be difficult to understand if i don't understand Mathematics, that's why i left that book . :-)
            It has nothing to do with mathematics, it's all just definitions. What (relevant)
            section of that JLS (Java Language Specification) don't you understand?
            Nested (static) interfaces are similar to nested (static) classes. btw understanding
            at least a bit of math comes in handy when you want to be a programmer.
            Also btw, why did you download the PDF version instead of the HTML version?

            kind regards,

            Jos

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by JosAH
              It has nothing to do with mathematics, it's all just definitions. What (relevant)
              section of that JLS (Java Language Specification) don't you understand?
              Nested (static) interfaces are similar to nested (static) classes. btw understanding
              at least a bit of math comes in handy when you want to be a programmer.
              Also btw, why did you download the PDF version instead of the HTML version?

              kind regards,

              Jos
              Ahh .... Right ...actually i tried to download but ....failed ...then i went for HTML ..it come properly ....!!!
              Yeah i understand ..i m trying grip the Core Java while i doing advanced programming ..i should take advantages of Java provides .....So i am trying to dig into deeper ....as soon as the Math concerns i ll consult with you; the math expert ...lol... :-)
              anyway thanks !

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                I hope you don't mind that I don't understand you at all now.

                kind regards,

                Jos

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Originally posted by JosAH
                  I hope you don't mind that I don't understand you at all now.

                  kind regards,

                  Jos
                  Oh............. :-)
                  Basically i move to and fro in JAVA.
                  But right now i got understood that before going to advance i have to grip all the basics...
                  I have lack of that one very much that's why i am trying to do that.
                  And yeah to be a programmer a bit of Mathematics knowledge should be there....:-)
                  I promise you that next time you will not misunderstand me....

                  Comment

                  • BigDaddyLH
                    Recognized Expert Top Contributor
                    • Dec 2007
                    • 1216

                    #10
                    Originally posted by dmjpro
                    Thanks that's what i expected .... so one more question ..what abut static and non-static inner interface?
                    I agree with JosH: The JLS is the Java Bible when it comes to definitive answers. It's not mathematics, but parts of it can be difficult to read because the Java language needs to be precisely defined. (If you think it's hard to read, try reading some legal documents!)

                    Anyway, it's also a good exercise to write a little code to test what you have read:

                    [CODE=Java]import java.lang.refle ct.Modifier;

                    interface I {
                    interface J {}
                    class C {}
                    }

                    class D {
                    interface K {}
                    class E {}
                    }

                    public class Testing {
                    public static void main(String[] args) {
                    test(I.class);
                    test(I.J.class) ;
                    test(I.C.class) ;
                    test(D.class);
                    test(D.K.class) ;
                    test(D.E.class) ;
                    }

                    static void test(Class x) {
                    int flags = x.getModifiers( );
                    System.out.prin tln("class " + x.getName() + ":");
                    System.out.prin tln("is static = " + Modifier.isStat ic(flags));
                    System.out.prin tln("is public = " + Modifier.isPubl ic(flags));
                    System.out.prin tln();
                    }
                    }[/CODE]

                    Was the output what you expected?

                    Comment

                    • dmjpro
                      Top Contributor
                      • Jan 2007
                      • 2476

                      #11
                      Thanks BigDaddyLH, Thanks a lot.
                      What Jos said that in interface fields are implicitly static public final and the methods are implicitly public and abstract. So the inner interfaces or classes will be static and public. But inside the class the inner interface is static. And class is as usual. So the inner interface is always static whether it is inside the class or interface. And inner interface is an instance variable that does not make sense.

                      Thanks Jos and Thanks BigDaddyLH.

                      Comment

                      • dmjpro
                        Top Contributor
                        • Jan 2007
                        • 2476

                        #12
                        I will read the full documents ..How Sun implements OOP in java.

                        Comment

                        Working...