Chapter-8-part1

Chapter-8-part1 - Chap9: it COE318 Fall 2008 Olivia Das...

Info icon This preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 1 Chap-9: Life and Scope of Reference Variables An object is alive as long as there are live references to  it. An object becomes eligible for garbage collection when  its last live reference dissappears.  Scope… will be discussed…
Image of page 1

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

View Full Document Right Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 2 Scope of reference variables public class Foo { private String s = new String(“ “); … … } public class Foo { public void f() { String s = new String(“ “); } }
Image of page 2
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 3 Exercise 1 public class A { public void foo() { bar(); } public void bar() { Dog d = new Dog(); } } Scope of d?? Life of the new Dog object?? A a = new A(); a.foo();
Image of page 3

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

View Full Document Right Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 4 Exercise 2 public class B { private Dog d = new Dog(); public void go() { d = new Dog(); } } Scope of d?? How many Dog objects created and Life of the Dog objects?? B b = new B(); b.go();
Image of page 4
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 5 Exercise 3 public class B { private Dog d = new Dog(); public void go() { d = null; } } B b = new B(); b.go(); Scope of d?? How many Dog objects created and Life of the Dog objects??
Image of page 5

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

View Full Document Right Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 6 Chapter 8 Part 1 POLYMORPHISM Abstract Classes Abstract Methods Polymorphism via inheritance
Image of page 6
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 7 Animal -picture -location +roam(): void +sleep(): void +makeNoise(): void Dog +makeNoise() Wolf +makeNoise() Cat +makeNoise() Tiger +makeNoise() Lion +makeNoise() Hippo +makeNoise() Canine +roam() Feline +roam() Wolf w = new Wolf(); Animal h = new Hippo(); Animal a = new Animal();
Image of page 7

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

View Full Document Right Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 8 Abstract Classes represents an abstract/generic concept in a class hierarchy cannot be instantiated can be subclassed, can have a superclass
Image of page 8
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 9 Animal <<abstract>> -picture -location +roam(): void
Image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern