File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface variable initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface variable initialization" Watch "Interface variable initialization" New topic

Interface variable initialization

Nikhil Bansal
Ranch Hand

Joined: Jan 24, 2005
Posts: 60
Hi All,

I am posting a ques frm the forum itself.

interface I{ int i = 1, ii = Main.out("ii", 2);}

interface J extends I{ int j = Main.out("j", 3), jj = Main.out("jj", 4);}

interface K extends J{ int k = Main.out("k", 5);}

public class Main {

public static void main(String args[]){


public static int out(String s, int i) {

System.out.println(s + "=" + i);
return i;

I think,in interface the variables must be initialized at thier declaration.But here the code is containing method calls.And also iam not able to understand the output.

Please Help Me

Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

Nikhil Bansal posted Halloween, 2006 06:27 AM
Hi All,

I am posting a ques frm the forum itself.

what was so bad in the explanation in this thread?


all events occur in real time
I agree. Here's the link:
subject: Interface variable initialization
It's not a secret anymore!