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;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
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.
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
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Developing computer interface
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education