Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested Interface

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a doubt regarding inner classes and interfaces. Can anyone please clarify this to me. Consider the below code and tell me why it gives error in the lines commented,



Thanks in advance.

Regards,
Jothi Shankar Kumar. S
 
Rajesh Kadle
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In both cases static reference is made to non-static fileds, hence the compiler error.

Static context relates to class, it works with class. It has no reference like this or super, so we cant access the non-static fields from static context.

Other way, accessing static fields from non-static context is allowed as each instance is related to the class.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,

I just want to know if in the above code, the line,

interface StaticMemberInterface_1{int kk = 2000;}

Is kk implicitly static?

Regards,
Jothi Shankar Kumar. S
 
Rajesh Kadle
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, all fields inside an interface are implicitly static and final.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic