TEST PAPERS - 1(a) can only be assigned to once. 1(b) a...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1(a) can only be assigned to once. 1(b) a per-class attribute; one copy of the attribute for the class 1(c) no, breaks encapsulation 1(d) x and y are the same object; x == y 1(e) many solutions are possible; one of the simplest is @Override public int compareTo (Person other ) 4 marks { return this.age – other.age; 2 marks } This solution is inconsistent because compareTo returns 0 if the ages are the same and the names are different (equals is false). 2(a) define state 2(b) define behavior 2(c) Class has poor encapsulation because of the public attribute. 1. A has no control over name 2. A cannot enforce any invariants on name 3. cannot change implementation of name without breaking client code 2(d) 1. private static attribute holding the singleton instance 2. private constructors 3. public static method to access the singleton 3(a) 100 main invocation a 1 b 5 3(b) 500 main invocation a 5 b 1 tmp 1 3(c) 1 5 500 swap invocation a 1 b 5 tmp 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4. public final class StringUtil
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

TEST PAPERS - 1(a) can only be assigned to once. 1(b) a...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online