public class Box {
private final int CAPACITY;
public Box(int c) { CAPACITY = c; }
public int getCap() { return CAPACITY; }
}
// ...
Box b = new Box(50);
System.out.println(b.getCap());What is printed?
- Acheck_circle
50
- B
Compile-time error: cannot assign final
- C
0
- D
null
Explanation
A blank final instance variable can be assigned exactly once in the constructor; this is allowed.