• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Val's Exam Question numer 54

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
I need some help I do not understand the output for the following code
================================================
public class Question54 {
static int i;
int j;
static {
System.out.print("("+i+")");
i=3;
System.out.print("("+i+")");
}
{
System.out.print("("+i+","+j+")"); //line 1
j=2;
System.out.print("("+i+","+j+")");
}
Question54(){
System.out.print("("+i+","+j+")");
}
public static void main(String[] args) {
System.out.print("("+i+")");
Question54 q54 = new Question54();
System.out.print("("+q54.i+","+q54.j+")");
}
}
==================================================
I got the out put
(0)(3)(3)(3,0)(3,2)(3,2)(3,2)
but I think line 1 supposed to print (3,0)
I tried it like this
==================================================
public class hey{
int j;
{
System.out.println(j);
j=2;
System.out.println(j);
}
public static void main(String args[]){
new hey();
}
}
==================================================
and get the out put 0 2 as expected why is that?
Thanx
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the question tabbed
 
Paulo Silveira
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are right
it prints 3,0
like vals answer!
[ May 26, 2002: Message edited by: Paulo Silveira ]
 
Jaffery Rab
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I got mixed up with order of execution....
Jaffery
 
reply
    Bookmark Topic Watch Topic
  • New Topic