• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface initialization

 
lavanya sankuappan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 809
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is this trial2??
 
Keith Lynn
Ranch Hand
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 809
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic