publicclass Thing { private int x; private int y; private static int z = 0; publ
ID: 3615249 • Letter: P
Question
publicclass Thing
{
private int x;
private int y;
private static int z = 0;
public Thing()
{
x = z;
y = z;
}
static void putThing(int a)
{
z = a;
}
}
Assume aprogram containing the class declaration defines three Thingobjects with the following statements:
Thingone = new Thing();
Thingtwo = new Thing();
Thingthree - new Thing();
a. Howmany separate instances of the x member exist?
b. Howmany separate instances of the y member exist?
c. Howmany separate instances of the z member exist?
d. Whatvalue will be stored in the x and y members of each object?
e. Writea statement that will call the putThing method.
Explanation / Answer
Thing Thing();
Thing two = new Thing();
Thing three - new Thing();
a. How many separate instances of the x member exist?
3 instances exist.
b. How many separate instances of the y member exist?
3 instances exist.
c. How many separate instances of the z member exist?
1 instance exists.
d. What value will be stored in the x and y members of eachobject?
zero ( 0 )
e. Write a statement that will call the putThing method.
one.putThing(3);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.