wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interface 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 initialization" Watch "interface initialization" New topic
Author

interface initialization

lavanya sankuappan
Greenhorn

Joined: Jun 02, 2006
Posts: 17
interface I
{
int i=1,ii=trial2.out("ii",2);
}

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

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


class test {
public static void main (String[] args)
{
System.out.println(J.i);
System.out.println(K.j);
}
static int out(String s,int i)
{
System.out.println(s +"=" +i);
return i;
}
}

output is
1
j=3
jj=4
3
i understand reason for the first three lines of output.but how come 3 is displayed.please explain?
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
What is this trial2??


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
When you print out K.j, it prints the statements from the method out. However, the value of K.j is 3 so it prints that.
lavanya sankuappan
Greenhorn

Joined: Jun 02, 2006
Posts: 17
sorry about that,actual code is

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

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

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


class test {
public static void main (String[] args)
{
System.out.println(J.i);
System.out.println(K.j);
}
static int out(String s,int i)
{
System.out.println(s +"=" +i);
return i;
}
}

output is
1
j=3
jj=4
3
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Then in that case the value returned from the out method is printed(which

is 3) in the end by the SOP() line of main method.
[ June 13, 2006: Message edited by: Naseem Khan ]
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
This thread.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: interface initialization