Statistics:
mean 19.476 (818.000/42) stddev 4.495 median 20.000 midrange 16.000-22.000 # avg 1 5.21 / 10 2 4.19 / 5 3 10.07 / 15
What distinguishes the purpose of a class method from an instance method? That is, how should you decide whether a particular behavior should be an instance method or a class method? (I am not asking how they are syntactically distinguished in Java. The syntactic distinction is that a class method includes a static keyword in its declaration, while an instance method does not.)
Name Java's seven primitive types other than boolean. For each, specify whether the type requires 8 bits, 16 bits, 32 bits, or 64 bits.
Define a Counter class to represent simple counting devices. It should include the following methods.
public static void run() { Counter a = new Counter(); Counter b = new Counter(); a.increment(); IO.println(a.getValue()); // prints ``1'' a.increment(); b.increment(); IO.println(a.getValue()); // prints ``2'' IO.println(b.getValue()); // prints ``1'' }
public class Counter { // : (your code here) }
byte | 8 |
short | 16 |
int | 32 |
long | 64 |
float | 32 |
double | 64 |
char | 16 |
public class Counter { private int val; public Counter() { val = 0; } public void increment() { val++; } public int getValue() { return val; } }