1 / 13

Thanks, Andrew.

Thanks, Andrew. Reminders: wear the wireless mike combination is 1-31 speak slowly, pause for questions I’d rather you get through less material than try to rush through the slides bring whiteboard markers/eraser make sure writing is LARGE ENOUGH to be seen in back of room use BOLD colors.

jaguar
Download Presentation

Thanks, Andrew.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Thanks, Andrew. • Reminders: • wear the wireless mike • combination is 1-31 • speak slowly, pause for questions • I’d rather you get through less material than try to rush through the slides • bring whiteboard markers/eraser • make sure writing is LARGE ENOUGH to be seen in back of room • use BOLD colors

  2. CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 645-4739 alphonce@buffalo.edu

  3. Agenda • Announcements • Cell phones / laptops off & away / Name signs out • Last time • Our second relationship: Association • Methods with parameters • Today • null • this (revisited) • interfaces (if time permits)

  4. Announcements • Exam 2 – three weeks away (Wednesday after spring break) • covers material from exam 1 up to & including 3/9 • review on Monday 3/19 • exam on Wednesday 3/21 • No recitations in exam week: 3/19 – 3/23

  5. ‘null’ • ‘null’ denotes the null reference, a reference which does not refer to any object. • We can use ‘null’ to solve the two dogs, one collar problem (see code on next slide):

  6. removeCollar rather than getCollar public class Dog { private Collar _collar; public Dog(Collar collar) { this._collar = collar; } public void setCollar(Collarcollar) { this._collar= collar; } public Collar removeCollar() { Collar temp = this._collar; this._collar = null; return temp; } }

  7. Can also use in constructor public class Dog { private Collar _collar; public Dog() { _collar = null; } . . . } Now a Dog can be created without a Collar

  8. Consider this code(assume association via constructor) fido rover 3500 4000 Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); fido – 3500 rover – 4000 fido’s _collar – 3600 rover’s _collar – 4100 two collars are at 4850 and 4925 • 4850 _collar • _collar 3500 3600 4000 4100 • 4925 4850 4925

  9. Consider this code(assume association via constructor) fido rover 3500 4000 temp Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); fido.setCollar(rover.removeCollar()); public Collar removeCollar() { Collar temp = _collar; _collar = null; return temp; } • 4850 _collar • _collar 3500 3600 4000 4100 • 4925 4850 4925

  10. Consider this code(assume association via constructor) fido rover 3500 4000 temp Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); fido.setCollar(rover.removeCollar()); public Collar removeCollar() { Collar temp = _collar; _collar = null; return temp; } • 4850 _collar • _collar 3500 3600 4000 4100 What happens here? Which _collar are we referring to here? • 4925 4850 4925

  11. thisthe object on which a method is invoked fido rover this 3500 4000 temp fido.setCollar(rover.removeCollar()); public Collar removeCollar() { Collar temp = _collar; _collar = null; return temp; } • 4000 • 4925 • 4850 _collar • _collar 3500 3600 4000 4100 What happens here? Which _collar are we referring to here? • 4925 4850 4925

  12. thisimplicitly in code fido rover this 3500 4000 temp fido.setCollar(rover.removeCollar()); public Collar removeCollar() { Collar temp = this._collar; this._collar = null; return temp; } • 4000 • 4925 • 4850 _collar • _collar 3500 3600 4000 4100 What happens here? Which _collar are we referring to here? • 4925 4850 4925

  13. this fido rover this 3500 4000 temp rover.setCollar(fido.removeCollar()); public Collar removeCollar() { Collar temp = this._collar; this._collar = null; return temp; } • 3500 • 4850 • 4850 _collar • _collar 3500 3600 4000 4100 What happens here? Which _collar are we referring to here? • 4925 4850 4925

More Related