Java question – Polymorphism?

class Cat {

String whatAmI() {
return “I’m a Cat!”;
}}

class Kitten extends Cat {

String whatAmI() {
return “I’m a Kitten!”;
}}

class NinjaKitten extends Kitten {

String isKickedBy(Kitten k) { return “Ouch!”; }
}

Cat bob = new NinjaKitten();
System.out.println(“Bob: ” + bob.whatAmI());

My question is what is bob’s static type and what is his dynamic type?

Subscribe / Share

One Comments Post a Comment
  1. Noah says:

    Bob’s static type would be Cat, and his dynamic type, NinjaKitten (which is awesome by the way).

    Hope that helps!

Leave a Reply




Categories

Powered by Yahoo! Answers