10-04 Class Notes CS 107

10-04 Class Notes CS 107 - ] 4. A Constructor should have...

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

View Full Document Right Arrow Icon
Announcements: Program #3 solution has been posted online. Midterm #1 solution has also been posted online, along with recent corrections. Questions? Last Time: Program #3 solution discussion, Some brief discussion of test, verbal course evaluation Continuation of Objects and Classes example, developing a robust Date class Problems / Solutions for various steps along the way: Can set invalid values Make data members (aka instance variables private and use get and set methods to manipulate those values. In the set methods we can add code to do error checking. 1. We'd like to set multiple values with a set method [ make extra methods ] 2. Can't set a month value with an int, as opposed to a String value [ overloading, private utility methods ] 3. methods can have same name , as long as they have a different argument signature . Argument signature is method name + the number and types of parameters. Currently we need two steps to create an object and then set its values [ Constructors
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ] 4. A Constructor should have same name as the class, should be public , and must not have a return type. Once you start creating constructors, you must also create the default constructor ('cause Java assumes you know what you're doing) We want to be able to share code between Constructors [ chaining using this ] 5. To chain constructors, simply put this and then the parenthesis with parameters. You can't call other methods before you call the chaining constructor call. How can we print out an object neatly? [ toString() method ] 6. Today: 10-04 Class Notes CS 107 Monday, October 04, 2010 12:08 PM 107 Fall 2010 Page 1 How can we do a deep comparison of objects? [ equals() method ] 7. How can we make a copy of an object? [ copy constructor ] 8. See code developed in class for these. Test your knowledge: How would we create a Book class? What should be in it? How would we create the driver to test it? 107 Fall 2010 Page 2...
View Full Document

This note was uploaded on 02/10/2012 for the course COP 2271 taught by Professor Reed during the Fall '10 term at University of Central Florida.

Page1 / 2

10-04 Class Notes CS 107 - ] 4. A Constructor should have...

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

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