Plz help me in understanding this ...
case1)
class Y3
{
static int test1()
{
System.out.println("from test1");
return 100;
}
static int test2()
{
System.out.println("from test2");
return test1();
}
public static void main(String[] args)
{
//test1();
//System.out.println(test2());
//System.out.println(test2()+test1());
test2();
}
}
output: from test2
from test1
So , when test2 is called in main method , the control went to test2() and started executing it , so when the ctl came to return of test2() , it saw test1() and ctl when to test1(), so when ctrl came to return of test1() ,, what happens then ??
case 2)
class Y3
{
static int test1()
{
System.out.println("from test1");
return 100;
}
static int test2()
{
System.out.println("from test2");
return 100;
}
public static void main(String[] args)
{
//test1();
//System.out.println(test2());
//System.out.println(test2()+test1());
test2();
}
}
output: from test2
In this case when ctl when to test2() and then to it return why its not printing its 100 . .. where as in case 1) , it executed its return thats why it when to test1() ..
Can any one explain me what is the correct way to understand this.
thanks
Abhishek