Consider the following program and answer the questions given below:
class sample
{ int a, b;
sample(int x, int y)
{ a=x,b=y;
}
void calculate()
{ int Z;
Z=atb;
System.out.println(z);
}
}
(a) Name the global variables.
(b) What are the method variables?
Solution
(a) Here global variables are those variables which are defined globally,so variables which are defined globally are:-
a,b
(b) Method variables are those variables which are defined inside the method or function,so method variables here are:-
x,y,z