InterviewSolution
| 1. |
What type of parameter passing does Java support? |
|
Answer» There are basically TWO types of parameter passing:
JAVA supports Pass by value. Passing by value means that when a method is called, a copy of the parameters is SENT to the memory. When we are using the parameters inside the method or the block, the actual arguments aren’t used but the copy of those arguments (formal parameters) are worked with. There is no change in the actual parameters. Passing by reference means that the changes in the parameters will be reflected in the original value . This occurs because the method RECEIVES the memory address of the parameters i.e. the address of the parameters. What Java does is that it passes the reference of the object by value. In Java, arguments are always passed by value irrespective of their original VARIABLE type. Each time a method is called, a copy is created in the stack memory and its version is passed to the method. There are two situations which arise:
|
|