• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

interface initialization

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is this trial2??
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This thread.
 
reply
    Bookmark Topic Watch Topic
  • New Topic