Q&A ICSE2014-03I #7417
Question:
Consider the following class:
public class myClass {
public static int x = 3, y = 4;
public int a = 2, b = 3; }
(i) Name the variables for which each object of the class will have its own distinct copy.
(ii) Name the variables that are common to all objects of the class.
Answer:
For static variables, all objects share a common copy while for non static variable, each object gets its own copy. Therefore, the answer
is
(i) a, b
(ii) x, y
