Lec 25 - Subtyping and Dynamic Dispatch

E it does not provide implementacons for all of its

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: es extend (possibly many) interfaces - Classes implement (possibly many) interfaces - Classes (except Object) extend exactly one other class (Object if implicit) - Interface types are “subtypes by fiat” of Object Other forms of inheritance •  Java has other features related to inheritance (some of which we will discuss later in the course): –  A subclass might override (re- implement) a method already found in the superclass –  A class might be abstract – i.e. it does not provide implementacons for all of its methods (its subclasses must provide them instead) •  These features are hard to use properly and the need for them arises in special cases –  Making reusable libraries –  Special methods: equals and toString •  We recommend avoiding all forms of inheritance (even “simple inheritance”) when possible – prefer interfaces and composicon (see Main3.java). Especially avoid overriding. The Java Abstract Stack Machine 1.  Class tables 2.  Constructors and “this” 3.  Dynamic dispatch 4.  Stacc class members What about nonstacc methods? •  What code gets run in a method invocacon? o.move(3,4);! •  When that code is running, how does it access the fields of the object that invoked it? ! ! ! ! !x = x + dx; ! •  When does the code in a constructor get executed? •  What about inheritance? Refinements to the Stack Machine •  Code is stored in a class table, which is a special part of the heap: –  –  –  ...
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