An encapsulation violation occurs when private information that should not be changed by external classes is (usually unintentionally) exposed to external modification. Consider the following (complete) Java class that is supposed to be immutable: 1. import java.awt.Point; 2. import java.math.BigDecimal; 3. public final class Encapsulation 4. ( 5. private final Point myPoint; 6. private final String[] myStrings; 7. private final BigDecimal myNumber; 8. public Encapsulation(final Point thePoint, final String[] theStrings, final BigDecimal theNumber) 9. { 18. myPoint - thePoint; 11. myStrings = theStrings; 12. myNumber = theNumber; 13.} 14. public Point getPoint() 15. { 16. return myPoint; 17. } 18. public String[) getStrings() 19. { 20. return (String[])myStrings.clone(); 21.} 22. public BigDecimal getNumber() 23. { 24. return myNumber; 25.} 26.} Does this class exhibit any encapsulation violations? If not, answer no, with brief reasons for why encapsulations did not occur. If yes, briefly describe each encapsulation violation and explain how you would fix it. Note that the class does compile as written, so do not look for syntax errors in the code.
An encapsulation violation occurs when private information that should not be changed by external classes is (usually unintentionally) exposed to external modification. Consider the following (complete) Java class that is supposed to be immutable: 1. import java.awt.Point; 2. import java.math.BigDecimal; 3. public final class Encapsulation 4. ( 5. private final Point myPoint; 6. private final String[] myStrings; 7. private final BigDecimal myNumber; 8. public Encapsulation(final Point thePoint, final String[] theStrings, final BigDecimal theNumber) 9. { 18. myPoint - thePoint; 11. myStrings = theStrings; 12. myNumber = theNumber; 13.} 14. public Point getPoint() 15. { 16. return myPoint; 17. } 18. public String[) getStrings() 19. { 20. return (String[])myStrings.clone(); 21.} 22. public BigDecimal getNumber() 23. { 24. return myNumber; 25.} 26.} Does this class exhibit any encapsulation violations? If not, answer no, with brief reasons for why encapsulations did not occur. If yes, briefly describe each encapsulation violation and explain how you would fix it. Note that the class does compile as written, so do not look for syntax errors in the code.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 20RQ
Related questions
Question
Question 10
![An encapsulation violation occurs when private information that should not be changed by external
classes is (usually unintentionally) exposed to external modification. Consider the following
(complete) Java class that is supposed to be immutable:
1. import java.awt.Point;
2. import java.math. BigDecimal;
3. public final class Encapsulation
4. {
5. private final Point myPoint;
6. private final String[] myStrings;
7. private final BigDecimal myNumber;
8. public Encapsulation(final Point thePoint,
final String[] theStrings,
final BigDecimal theNumber)
9. {
10. myPoint - thePoint;
11. myStrings = theStrings;
12. myNumber = theNumber;
13.}
14. public Point getPoint()
15. {
16. return myPoint;
17.}
18. public String[) getStrings()
19. {
20. return (String[])myStrings.clone();
21.}
22. public BigDecimal getNumber()
23. {
24. return myNumber;
25.}
26. }
Does this class exhibit any encapsulation violations? If not, answer no, with brief reasons for why
encapsulations did not occur. If yes, briefly describe each encapsulation violation and explain how
you would fix it. Note that the class does compile as written, so do not look for syntax errors in the
code.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7384a12d-4ddb-481d-975e-5adc1f339d9e%2Fdc33ad4e-b303-4e7a-addc-633cc0ab95ae%2Fosnu5if_processed.png&w=3840&q=75)
Transcribed Image Text:An encapsulation violation occurs when private information that should not be changed by external
classes is (usually unintentionally) exposed to external modification. Consider the following
(complete) Java class that is supposed to be immutable:
1. import java.awt.Point;
2. import java.math. BigDecimal;
3. public final class Encapsulation
4. {
5. private final Point myPoint;
6. private final String[] myStrings;
7. private final BigDecimal myNumber;
8. public Encapsulation(final Point thePoint,
final String[] theStrings,
final BigDecimal theNumber)
9. {
10. myPoint - thePoint;
11. myStrings = theStrings;
12. myNumber = theNumber;
13.}
14. public Point getPoint()
15. {
16. return myPoint;
17.}
18. public String[) getStrings()
19. {
20. return (String[])myStrings.clone();
21.}
22. public BigDecimal getNumber()
23. {
24. return myNumber;
25.}
26. }
Does this class exhibit any encapsulation violations? If not, answer no, with brief reasons for why
encapsulations did not occur. If yes, briefly describe each encapsulation violation and explain how
you would fix it. Note that the class does compile as written, so do not look for syntax errors in the
code.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr