• Post Reply Bookmark Topic Watch Topic
  • New Topic

Same variable from two implemented interfaces  RSS feed

 
Abhra Kar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we call System.out.println(count); then erroe message shows like "The field is ambiguous.
Why two count variable separately present here which can be access through there respective interfaces.Why not one interface count variable hide another interface's count variable.Please explain internally what happens?

Thanks
Abhra
 
Paweł Baczyński
Bartender
Posts: 2085
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A variable declared in an interface is always implicitly static.
Therefore AA.count and BB.count are different variables independent on each other.
By the way, what would you expect to print with System.out.println(count)?
 
Abhra Kar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought as BB interface implemented last so it's count variable hide AA's count variable and always print 20
 
Paweł Baczyński
Bartender
Posts: 2085
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The order of interfaces listet does not matter.
 
Abhra Kar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okk
Thanks a lot Pawel
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!