File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reply to Q Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Reply to Q" Watch "Reply to Q" New topic
Author

Reply to Q

Karthik Subramanian
Greenhorn

Joined: Aug 23, 2000
Posts: 27

Hi KS,
If your Question is how to go about changing the values
of the local variables a,b and c by passing them to a method then i don't think it could be done.
But if you don't mind having them as instance variables
then the job becomes easy.You can do it too!!
anyway i hope i am answering your question with the following
code below
class A
{
int a = 10,b = 20, c=30;
public static void main(String [] args)
{
A x = new A();
x.test();
}
void test()
{
System.out.println("Before a = " + a);
System.out.println("Before b = " + b);
System.out.println("Before c = " + c);
A y = calculate(this);
System.out.println("after a = " + y.a);
System.out.println("after b = " + y.b);
System.out.println("after c = " + y.c);
}
A calculate(A z)
{
z.a *= 2;
z.b *= 3;
z.c *= 4;
return z;
}
}
 
 
subject: Reply to Q
 
Threads others viewed
Argument Passing
Static values don't get serialized, yet the code seems to show the contrary
Generic Class: Calculating with generic Typs
Garbage collection doubt
how many objects will be eligible for garbage collection
IntelliJ Java IDE