Copy constructor and defensive copy
Java
Medium
6 views
Problem Description
Task: create a class Team holding int[] scores. Use defensive copy in constructor.
Output Format
Return value
Constraints
Do not expose internal array.
Official Solution
static class Team{private final int[] scores;Team(int[] s){scores=new int[s.length];for(int i=0;i<s.length;i++) scores[i]=s[i];}int getScore(int i){return scores[i];}}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!