Can i acces non static Global varible in non static function | Selenium Forum
M
Posted on 05/09/2015
Ex :

public class Test {
int i=100;
static int j=11;

public static void main(String[] args) {

System.out.println(j);
}
public void non_static(){

System.out.println(i);


}

}
o/p : // am expecting i value should print 100 ,
here showing o/p only static j vale is 11

M
Replied on 06/09/2015

[quote="sivanna48@gmail.com":2bk43q59]
o/p : // am expecting i value should print 100 ,
here showing o/p only static j vale is 11[/quote:2bk43q59]

[quote="sivanna48@gmail.com":2bk43q59]Ex :

public class Test {
int i=100;
static int j=11;

public static void main(String[] args) {

System.out.println(j);
}
public void non_static(){

System.out.println(i);


}

}[/quote:2bk43q59]


because you're only printing j
System.out.println(j);

you're not printing i

you have made a function non_static but not calling it.
do this


[quote="sivanna48@gmail.com":2bk43q59]Ex :

public class Test {
int i=100;
static int j=11;

public static void main(String[] args) {

System.out.println(j);
non_static();

}
public void non_static(){

System.out.println(i);


}

}[/quote:2bk43q59]

this will print both.