Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Arland Smith   on Oct 25 In Java Category.

  
Question Answered By: Brian Ross   on Oct 25

You infact call the second method  before the main  method ends.

So you are right the main method fires first, but if you call something
else from the main method it will run the called bits from the main method.

<main()>
int z = foo(x,y);

System.out.println("x is " + x);
</main()>

To find the value of Z, it must run the method foo(x,y). It can't go on
untill it has the answer for the variable z.

However if you where to do something like ...

public static  void main(String[] args) {

int x = 6;

int y = 3;

int z;

System.out.println("x is " + x);

z = foo(x, y);
}

Your out put would be right.

The reson for this is that you are finding the actual value for z after
you printout the results of x.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on main method Or get search suggestion and latest updates.


Tagged: