Question
class access{
public int x;
static int y;
void cal(int a, int b){
x += a ;
y += b;
}
}
class static_specifier {
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
obj1.y = 0;
obj1.cal(1, 2);
obj2.x = 0;
obj2.cal(2, 3);
System.out.println(obj1.x + " " + obj2.y);
}
}
What is the output of this program?
class access{
public int x;
static int y;
void cal(int a, int b){
x += a ;
y += b;
}
}
class static_specifier {
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
obj1.y = 0;
obj1.cal(1, 2);
obj2.x = 0;
obj2.cal(2, 3);
System.out.println(obj1.x + " " + obj2.y);
}
}
Answer: Option D
Was this answer helpful ?
None.
output:
$ javac static_specifier.java
$ java static_specifier
1 5
Was this answer helpful ?
More Questions on This Topic :
Question 8.
Which of these methods must be made static?
....
Submit Solution