KEMBAR78
CS 1331A, Spring 2016 Pop Quiz 2 2/22/16: Name: - T ID | PDF
0% found this document useful (0 votes)
42 views1 page

CS 1331A, Spring 2016 Pop Quiz 2 2/22/16: Name: - T ID

The code defines a Quiz class with static and non-static fields alpha and beta. It creates two Quiz objects x and y, increments their fields separately and together, and prints the results. The code will print 1 1, 2 2, and 3 3 on separate lines as it increments the objects' fields individually and together through the main method.

Uploaded by

Claire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views1 page

CS 1331A, Spring 2016 Pop Quiz 2 2/22/16: Name: - T ID

The code defines a Quiz class with static and non-static fields alpha and beta. It creates two Quiz objects x and y, increments their fields separately and together, and prints the results. The code will print 1 1, 2 2, and 3 3 on separate lines as it increments the objects' fields individually and together through the main method.

Uploaded by

Claire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

CS 1331A, Spring 2016 Name:___________________________

Pop Quiz 2
2/22/16 T2 ID:___________________________

1. What will the code below print out?

public class Quiz {


private int alpha=0;
private static int beta=0;

public void increment() {


alpha++;
beta++;
}

public void display() {


System.out.println(alpha+" "+beta);
}

public static void main(String[] args){


Quiz x = new Quiz();
Quiz y = new Quiz();

x.increment();
y.increment();
x.increment();

x.display(); // printing happens here


y.display(); // printing happens here

x = y;
x.increment();

x.display(); // printing happens here


y.display(); // printing happens here
}
}

You might also like