1 / 7

Example

Example. Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); rover.setCollar( fido.getCollar() );. Dog fido = new Dog( new Collar() ); Dog rover = new Dog(new Collar()); rover.setCollar(fido.getCollar());. fido. Collar object.

beulah
Télécharger la présentation

Example

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. Example Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); rover.setCollar(fido.getCollar()); CSE 115/503 Introduction to Computer Science for Majors I

  2. Dog fido = new Dog(new Collar());Dog rover = new Dog(new Collar());rover.setCollar(fido.getCollar()); fido Collar object CSE 115/503 Introduction to Computer Science for Majors I

  3. Dog fido = new Dog(new Collar());Dog rover = new Dog(new Collar());rover.setCollar(fido.getCollar()); collar _collar fido Dog object Collar object The expression new Collar() produces a reference to the new object. The reference is assigned to the parameter “collar”, and then, via the assignment statement in the constructor, to the instance variable _collar. CSE 115/503 Introduction to Computer Science for Majors I

  4. Dog fido = new Dog(new Collar());Dog rover = new Dog(new Collar());rover.setCollar(fido.getCollar()); _collar fido Dog object Collar object CSE 115/503 Introduction to Computer Science for Majors I

  5. Dog fido = new Dog(new Collar());Dog rover = new Dog(new Collar());rover.setCollar(fido.getCollar()); _collar fido Dog object Collar object _collar rover CSE 115/503 Introduction to Computer Science for Majors I

  6. Dog fido = new Dog(new Collar());Dog rover = new Dog(new Collar());rover.setCollar(fido.getCollar()); _collar fido collar Dog object Collar object _collar rover The expression fido.getCollar() produces a reference to fido’s collar object. This reference is assigned to the parameter “collar”, and then, via the assignment statement in the constructor, to rover’s _collar instance variable. CSE 115/503 Introduction to Computer Science for Majors I

  7. Dog fido = new Dog(new Collar());Dog rover = new Dog(new Collar());rover.setCollar(fido.getCollar()); _collar fido Dog object Collar object _collar rover CSE 115/503 Introduction to Computer Science for Majors I

More Related