Doubt in interface...

interface I {

int f(int x);

int var = 4;

}

public class C implements I {

public int f(int x) {

return x * x;

}

public static void main(String[] args) {

try

{

I[] a = new C[I.var];

System.out.println(a.length);

System.out.println(a[0]);//output - null

System.out.println(a[1]);//output - null

System.out.println(a[2]);//output - null

System.out.println(a[3]);//output - null

for (int i=0; i<a.length; ++i)

{

System.out.println(a.f(i));// Null pointer exception

}

}catch (Exception e){

System.out.println("Error: "+e.getMessage());// error in this line

e.printStackTrace();

}//catch

}//main

}//class

question: i have to call f() which is in interface a.length times. how?>

[852 byte] By [dhamu123a] at [2007-11-27 4:30:56]
# 1
Multiple-post http://forum.java.sun.com/thread.jspa?threadID=5173053&tstart=0Original has formatting
cotton.ma at 2007-7-12 9:40:19 > top of Java-index,Java Essentials,New To Java...