0923 - Dynamic dispatch again Static members Extra office...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Dynamic dispatch again Static members
Background image of page 1

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

View Full DocumentRight Arrow Icon
Extra office hours this week Extra office hours this week Brent: Wednesday, Moore 100A it is, 5-7PM Alexey: Thursday 5-7, location TBA No office hours for Brent on Friday 9/23/09 2
Background image of page 2
Sample Exams Posted on class web site 9/23/09 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
HW2 9/23/09 4
Background image of page 4
Inheritance of fields 9/23/09 5 public class Item { protected Container container; protected String description; ... } public class Character extends Item { ... } Since Character extends Item, every Character will automatically inherit the fields container and description – no need for Character to declare its own container or description!
Background image of page 5

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

View Full DocumentRight Arrow Icon
CONSTRUCTORS AGAIN 9/23/09 6
Background image of page 6
Constructors and Overloading Constructors can be overloaded: A class can have many constructors, differing in the number and/or types of parameters We’ll come back to the topic of overloading later, but here’s a little example. .. 9/23/09 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
9/23/09 8 public class Rectangle { private Point lowerLeft; private double width, height; public Rectangle(Point lowerLeft, double width, double height) { this.lowerLeft = lowerLeft; this.width = width; this.height = height; } public Rectangle(double width, double height) { this.lowerLeft = new Point(0,0); this.width = width; this.height = height; } public double getX() { . .. } public double getY() { . .. } public void move(double dx, double dy) { . .. } }
Background image of page 8
9/23/09 9 ... Point p = new Point(0,0); Rectangle r1 = new Rectangle(p,1,1); Rectangle r2 = new Rectangle(2,2);
Background image of page 9

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

View Full DocumentRight Arrow Icon
Constructors and Inheritance Constructors are not inherited But one constructor can invoke another. .. A constructor can use either “this” or “super” in its first line (only), to invoke another constructor in the same class definition (this) or its superclass (super) Otherwise, an implicit call to super() is inserted at the beginning 9/23/09 10
Background image of page 10
9/23/09 11 public class Rectangle { private Point lowerLeft; private double width, height; public Rectangle(Point lowerLeft, double width, double height) { this.lowerLeft = lowerLeft; this.width = width; this.height = height; } public Rectangle(double width, double height) { this(new Point(0,0), width, height); } public double getX() { . .. } public double getY() { . .. } public void move(double dx, double dy) { . .. } }
Background image of page 11

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

View Full DocumentRight Arrow Icon
9/23/09 12 public class Square extends Rectangle { public Square(Point lowerLeft, double side) {
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 04/22/2010.

Page1 / 40

0923 - Dynamic dispatch again Static members Extra office...

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

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