+ 1
can we declare the variables globally??
4 Réponses
+ 1
yes you can declare a variable as global.
-> if you want to use your variable inside class then declare it as instance variable(class level).
-> if you want to use your variable outside class and within same package declare as protected or public and class as protected or public.
-> if you want to use your variable outside class as well as outside package then you must declare your variable as well as your class as public.
hope you got some clarity...
0
Declare it public
0
private static int x;
// the variable of your choice must be placed where 'x' is located in this example and the type is where ive put 'int'
// then declare the following opening line of your array
public static void main(String[] args) {
// Hope this helps
0
yes you can