turing equivalent
Author |
Message |
Homer_simpson
|
Posted: Fri Feb 13, 2004 2:11 pm Post subject: turing equivalent |
|
|
you know in turing when u wanna declare a procedure that could change the value of arguments you would go like this:
procedure blah(var args:int)
args:=3
end blah
now in java when i make a procedure... i can't change the value of my arguments inside my procedure... i need to know how to do that... |
|
|
|
|
|
Sponsor Sponsor
|
|
|
rizzix
|
Posted: Fri Feb 13, 2004 3:42 pm Post subject: (No subject) |
|
|
well if it is a primitive: int, double, float, char, byte, short, long etc... you can't since primitives are passed my value. What u can do is use the Integer, Float, Double... etc.. encapsulation classes instead. Objects are passed by reference. so yep! you can do that. but i should point out.. thats bad coding in java terms.
in java, in fact most pure OOP languages: never change the contents of the arguments unless absolutely necessary |
|
|
|
|
|
wtd
|
Posted: Fri Feb 13, 2004 5:49 pm Post subject: (No subject) |
|
|
Indeed, the only way you could achieve something like this is by having the procedure alter an instance or static variable.
code: | import java.lang.*;
import java.io.*;
import java.util.*;
class Test
{
private static int number;
private static void addOneToNumber()
{
number = number + 1;
}
private static void main(String[] args)
{
number = 41;
addOneToNumber();
}
} |
|
|
|
|
|
|
Homer_simpson
|
Posted: Fri Feb 13, 2004 8:18 pm Post subject: (No subject) |
|
|
well... that makes a lota sense... i think i'm gonna make a separete class just for that specific object of mine... thx for the response... + bits |
|
|
|
|
|
|
|