Chapter-8-part1

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

Info iconThis 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…
Background image of page 1

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

View Full DocumentRight 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(“ “); } }
Background 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();
Background image of page 3

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

View Full DocumentRight 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();
Background 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??
Background image of page 5

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

View Full DocumentRight 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
Background 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();
Background image of page 7

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

View Full DocumentRight 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
Background image of page 8
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 9 Animal
Background image of page 9

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

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

This note was uploaded on 12/12/2010 for the course COE 318 taught by Professor Ken during the Spring '08 term at Ryerson.

Page1 / 27

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

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online