This program gives output -
A 1 2
Shouldn't it give output -
1 A 2
since first a.i should print 1 and then a.getI() executes and should print A 2
public class A1{
int i=1;
public int getI(){
System.out.print("A ");
return i+1;
}
public static void main(String args[]){
A1 a=new A1();
System.out.print(a.i+" "+a.getI());
}
}
In this expression:
a.i+" "+a.getI()
The call to a.getI()
gets evaluated first, and afterwards the string is formed by concatenating a.i
plus a.getI()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With