Lec 25 - Subtyping and Dynamic Dispatch

Int x dget object x inity 2 string tostring

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Decr! extends Counter ! Decr(int initY) { … }! void dec(){incBy(-y);}! Done with the call Workspace ;! Stack Heap Class Table Decr! Decr d = _;! d.dec();! int x = d.get();! Object! x! initY! 2! String toString(){… ! y! this! 0! 0! boolean equals…! …! _;! this.y = initY;! Counter! this! Done with the call to “super”, so pop the stack to the previous workspace. extends Object ! Counter() { x = 0; }! void incBy(int d){…}! int get() {return x;}! Decr! extends Counter ! Decr(int initY) { … }! void dec(){incBy(-y);}! Concnuing Workspace Stack this.y = initY;! Heap Decr d = _;! d.dec();! int x = d.get();! Class Table Decr! Object! x! initY! 2! String toString(){… ! y! this! 0! 0! boolean equals…! …! Counter! extends Object ! Concnue in the Decr class’s constructor. Counter() { x = 0; }! void incBy(int d){…}! int get() {return x;}! Decr! extends Counter ! Decr(int initY) { … }! void dec(){incBy(-y);}! Abstract Stack Machine Workspace this.y = 2;! Stack Heap Class Table Decr! Decr d = _;! d.dec();! int x = d.get();! Object! x! initY! 2! String toString(){… ! y! this! 0! 0! boolean equals…! …! Counter! extends Object ! Counter() { x = 0; }! void incBy(int d){…}! int get() {return x;}! Decr! extends Counter ! Decr(int initY) { … }! void dec(){incBy(-y);}! Assigning to a field Workspace this.y = 2;! Stack Heap Class Table Decr! Decr d = _;! d.dec();! int x = d.get();! Object! x! initY! 2! String toString(){… ! y! this! 0! 2! boolean equals…! …! Counter! extends Object ! Assignment into the this.y field. (This really takes two steps as we saw earlier, but we’re skipping some for the sake of brevity…) Counter() { x = 0; }! void incBy(int d){…}! int get() {return x;}! Decr! extends Counter ! Decr(int initY) { … }! void dec(){incBy(-y);}! Done with the call Workspace ;! Stack Heap Class...
View Full Document

This note was uploaded on 10/23/2012 for the course CIS 121 taught by Professor Tannen during the Spring '09 term at UPenn.

Ask a homework question - tutors are online