Variable Storage and Global Variables in Java
hi
i had two querys..so please answer me if u have time
1. why a single value can be stored in a variable ? why cant we store two values ? i mean int a=5 means 5 is stored in a variable a...why cant we store 2 values..i want to know the exact reason.. ?
2.Why global varaibles concept is not present in java ? Is there any security problem or referrential transparency problem ? if not how can we implement that functionality ?
Re: Variable Storage and Global Variables in Java
Quote:
why cant we store two values
That is true of many things. Either it has one value or another value. What things can you think of that can have more than one value?
Re: Variable Storage and Global Variables in Java
You can store 32 bit values in an int. And appoximately infinitely many in a BigDecimal (*).
public class Global {static int answer = 42;}
(*) nyah, nyah
Re: Variable Storage and Global Variables in Java
You can have globally accessible variables as shown by pbrockway, but they're frowned upon as bad coding practice.
Constants, no problem, but variables aren't generally a good idea.