• 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

member method's variable assignment

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody tell me why this program is not giving values 10? It gives 0 actually.
public class Test {
private int i = giveMeJ();
private int j = 10;
int giveMeJ() { return j; }
public static void main ( String args[] )
{
System.out.println((new Test()).i );
}
}

Regards,
Veer
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think instance varibles are initialised in the order they are declared. When variable 'i' is initialised before variable 'j'.

Following code will result in 10.
private int j=10;
private int i=givemeJ();
Correct me if I am wrong.
regards,
Usha
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic