Welcome Guest | Sign in | Register
Flow Control - Discussion Page For Q.2786 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Flow Control > Questions and Answers

Q: class A{
Public static void main(String args[]){
int i=10;
i=test(i);
System.out.println(i);
}
Public static int test(int i){
i=200;
return I;

}
}
A. compile time error B. run time error
C. 10 D. 200

Answer and Explanation

Answer:200

Explanation:
here the code which we have in main method will execute, and test() method we are calling by passing I variable value , and that test() method returns value 200, that value will be stored in I variable , so previous value of the I variable is vanished now , new value 200 will be stored in I variable , then that value will be printed in output. To call test() method no need to create an object because test() method is declared as static ,so memory will be allocated automatically. You can call directly.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.