Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

interface

Status
Not open for further replies.

deva1

Programmer
Oct 28, 2002
27
US
package scjp;

abstract interface Myinter {
static final int i = 5;
void fun();
}

public class interface2 implements Myinter{

static int i=7;

public void fun(){
System.out.println(i);
}
public static void main(String[] args){

Myinter m = new interface2();
m.fun();
System.out.println(m.i);
}
}


The answer is 7 and 5.


My question is all the variables in an interface is implicitly public,static and final.Then how can we change the valiue of i in class interface2 which implements the interface Myinter.I am confused.please help


Thanks
 
Your namings are confusing.

"Myinter m" is of class "interface2" but it isn't an interface.

It's a class, implementing an interface.

m.i is the 'static int i = 7' which is hiding the 'Myinter.i'.

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top