I have doubt in the below code from the excercise module 3.How can we use i,j global non static variable in the static function add(int i,int j)? | Selenium Forum

I have doubt in the below code from the excercise module 3.How can we use i,j global non static variable in the static function add(int i,int j)?

D
dasmadhusmita99 Post on 12/03/2020

public class quiz1 {
int i;
int j;
public static void main(String[] args) {
quiz1 t1 = new quiz1();
t1.i=200;
t1.j=100;
add(t1.i,t1.j);
System.out.print(t1.i);
System.out.print(t1.j);
}

public static void add(int i,int j) {
i=i+100;
j=j+100;
System.out.print(i);
System.out.print(j);

S

Instructor

Support Team Reply on 13/03/2020

Whenever we declare a variable inside the function, even if it is declared globaly. It automatically ignores the global declaration and the values are retained for the local variable only.