Lec 25 - Subtyping and Dynamic Dispatch

Extends object counter x 0 void incbyint d int

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: or •  Remember that invoking a method/constructor pushes the saved workspace, the method params (none here) and a new this pointer. 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 super();! this.x = 0;! 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! (Running Object’s default constructor omiled.) 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.x = 0;! 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! Assignment into the this.x field goes in two steps: - look up the value of this in the stack - write to the “x” slot of that object. 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 .x = 0;! 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! Assignment into the this.x field goes in two steps: - look up the value of this in the stack - write to the “x” slot of that object. extends Object ! Counter() { x = 0; }! void incBy(int d){…}! int get() {return x;}!...
View Full Document

Ask a homework question - tutors are online