ch03ExSol - Chapter 3 Review Exercise Solutions R3.1 An...

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

View Full Document Right Arrow Icon
Chapter 3 Review Exercise Solutions R3.1 An interface is the public view of a class. It tells a program using the class what the functionality is, and how to use it. It does not disclose any details on how things are actually done. An implementation of a class is the actual code for accomplishing the tasks. R3.2 Encapsulation is the process of hiding implementation details while publishing an interface for programmers to use. If you hide the implementation details, you can diagnose errors and make changes and improvements to the implementation of a class without disrupting the work of programmers who use the class. R3.3 The private reserved word prevents a programmer using the class from manipulating instance variables except through the methods of that class. A programmer must use the public interface—the public methods that access or modify the instance variables—to change them. R3.4 private String value; or a more descriptive name private String grade; R3.5 Represent the time as one entire string value, example “8:35 a.m.” private String value; or as individual components private int hour; private int minute; private String meridian; R3.6 The programmers using the Time class do not have to do anything. That is the purpose of encapsulation and using a public interface. 1
Image of page 1

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

View Full Document Right Arrow Icon
R3.7 That depends on what you intend for the Counter class to do. Normally, no, you would not provide a setValue method because the counter, as described, should always start at zero. It
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern