Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CSE 115/503 Introduction to Computer Science for Majors I1 Example Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); rover.setCollar(fido.getCollar());"— Presentation transcript:

1 CSE 115/503 Introduction to Computer Science for Majors I1 Example Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); rover.setCollar(fido.getCollar());

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

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

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

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

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

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


Download ppt "CSE 115/503 Introduction to Computer Science for Majors I1 Example Dog fido = new Dog(new Collar()); Dog rover = new Dog(new Collar()); rover.setCollar(fido.getCollar());"

Similar presentations


Ads by Google