variables in interface

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Time
    New Member
    • Jan 2010
    • 77

    variables in interface

    Hi ppl,
    I read in 2-3 books that variables declared in interface are implicitly final,static and classes implementing it cant change its value.
    But i changed the value of variable which i had defined in an interface; it worked well.. i even changed its type; from int to char it still worked well.
    I even executed my program without defining that variable; it still worked fine.
    Does this mean interface makes it necessary only for methods to be implemented by implementing classes and not variables?..des pite of the fact given in Complete reference of Java and some other books?
  • lini
    New Member
    • Mar 2007
    • 12

    #2
    Can you post some code here?

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Interfaces define methods, not properties.

      Comment

      • Time
        New Member
        • Jan 2010
        • 77

        #4
        I got the answer.
        Actually variables defined in an interface can be directly used by a class implementing that interface; no need for redefining them like methods.
        If you use same variable name with diff. type; its treated as diff. variable from that defined in an interface; its given more priority and no error is generated.

        Comment

        Working...