Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

Passing Primitive Variables
When we passed to the primitive variable is passed to a method , we can see in this code : 
class ReferenceTest {
public static void main (String [] args) {
int a = 1;
ReferenceTest rt = new ReferenceTest();
System.out.println("Before modify() a = " + a);
rt.modify(a);
System.out.println("After modify() a = " + a);
}
void modify(int number) {
number = number + 1;
System.out.println("number = " + number);
}
}
      In this folowing code , we can see thet the variable a is passed to a method called modify(),
which increments the variable by 1.and now we know that whats the output of the givn code : 
C:Java ProjectsReference>java ReferenceTest
Before modify() a = 1
number = 2
After modify() a = 1
         
Posted By: Name:Rajesh Kr URL: Passing Primitive Variables