1 / 10

CSE115: Introduction to Computer Science I

CSE115: Introduction to Computer Science I. Dr. Carl Alphonce 219 Bell Hall 645-4739 alphonce@buffalo.edu. Announcements. I did not lecture from slides. I showed a demo of ‘green’ for UML class diagrams. I showed a demo of the lab 4 solution. We talked about ‘null’, the null reference.

Download Presentation

CSE115: Introduction to Computer Science I

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. CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 645-4739 alphonce@buffalo.edu

  2. Announcements • I did not lecture from slides. • I showed a demo of ‘green’ for UML class diagrams. • I showed a demo of the lab 4 solution. • We talked about ‘null’, the null reference. • We ended with a puzzle.

  3. Attendance • I checked attendance today: • 72% of registered students attended • 28% of registered students did not attend • Lecture and lab attendance is closely linked with success in the course: • students who do NOT attend regularly tend to fail • students who do attend regularly tend to pass (with good grades)

  4. ‘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):

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

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

  7. Consider this code(assume association via constructor) fido rover 1025 825 Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); 800 1000 _collar • _collar 800 825 1000 1025

  8. Consider this code(assume association via constructor) fido rover temp 1025 825 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; } 800 1000 _collar • _collar 800 825 1000 1025

  9. Consider this code(assume association via constructor) fido rover temp 1025 825 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; } 800 1000 _collar • _collar 800 825 1000 1025 What happens here? Which _collar are we referring to here?

  10. Puzzle to think about…

More Related