Submitted by Annu on Thu, 09/11/2008 - 23:36.
public interface IContext
{
public double originX = 0;
}
public interface IShape extends IContext
{
public double originX = 10;
}
public class Draw implements IShape
{
public Draw()
{
double originX = this.originX;
}
}
First, all members in an interface are implicitly static & final. Another thing to note is that static variables can be accessed in a class instance using the "this" keyword i.e. static variables are available to instances of a class, it is not possible the other way around.
Now when the jvm comes to the constructor of class Draw, here's the steps that it takes to determine the value of this.originX
Do note that, In the context of a class instance originX in interface IShape has shadowed originX from interface IContext.
Now were we to change the implementation of class Draw as follows
Let's see what the jvm doesHTH
Ashish Hareet
iRix Technologies.