Passing Primitive Variables

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
        

By:UMANG
Date:2027-02-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related scjp1.5 chap3 Links

scjp1.5 chap3 interview questions and answers for experienced and fresher