Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface implementation issue

 
vineet walia
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



i have to print f1 interface variable
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Your code will not compile because reference to i is ambiguous, both variable i in f1 and variable i in f2 match
so you have to use f1.i
 
vineet walia
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot
 
Rohini Shirpewar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should work.

 
Hareendra Reddy
Ranch Hand
Posts: 173
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

variables declared inside a interface are implicitly public ,static and final,
So, we can refer to the desired variable by using qualified name with interface type..

Can some one explain how to access the super class instance variable of same name....



Hoe to access the f3 version of variable i ??
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Hareendra
You can start new thread and ask question about super class and sub class issue because subject line of thread is interface implementation issue.
 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would the i not be overridden if one interface extends another?
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Overriding happens with instance method
See OverridingVsHiding
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hareendra,

You can access the value of i of f3 as mentioned below -

 
Hareendra Reddy
Ranch Hand
Posts: 173
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Salil...
 
Eric Kizaki
Greenhorn
Posts: 12
Eclipse IDE Google Web Toolkit Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic