11-07feb27casting

11-07feb27casting - 1 CS100J 27 February 2006 Casting About...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 1 CS100J 27 February 2006 Casting About 1. Casting between classes 2. Apparent and real classes. 3. Operator instanceof Procrastination Leave nothing for to-morrow that can be done to-day. Lincoln How does a project get a year behind schedule? One day at a time. Fred Brooks I don't wait for moods. You accomplish nothing if you do that. Your mind must know it has got to get down to work. Pearl S. Buck When I start a new project, I procrastinate immediately so that I have more time to catch up. Gries 1. The class hierarchy 2. function equals Study Secs 4.2 and 4.3 in text Buy a poster with the procrastinator’s creed here: http://www.art.com/asp/ sp-asp/_/pd--10001845/Procrastinators_Creed.htm After today, you have learned ALL the basics of classes, and done extremely well. Be proud of yourselves. 2 Class Animal public class Animal { private String name; // name of the animal private int age; // age of animal /** Constructor: an Animal with name n, age a */ public Animal(String n, int a) { name= n; age= a; } /** = "this Animal is older than h" */ public boolean isOlder(Animal h) { return this.age > h.age; } /** = the noise that the animal makes -- "" in class Animal */ public String getNoise () { return ""; } /** = the name of this Animal */ public String getName() { return name; } /** = a description of this Animal */ public String toString() { return "Animal " + name + ", age " + age; } } We put each method on one line to save space on the slide. Don’t do it in your program. a0 Animal name age Animal(String, int) isOlder(Animal) getNoise() getName() toString() 3 Class Cat /** An instance is a cat */ public class Cat extends Animal { /** Constructor: a Cat with name n and age a */ public Cat(String n, int a) { super (n, a); } /** = the noise this cat makes */ public String getNoise() { return "meow"; } /** = a description of this Cat */ public String toString() { return super .toString() + ", noise " + getNoise();....
View Full Document

This note was uploaded on 03/03/2012 for the course CS 100J taught by Professor Davidgries during the Spring '07 term at Cornell.

Page1 / 14

11-07feb27casting - 1 CS100J 27 February 2006 Casting About...

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

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