polymorphism in java - JSP/Java Views : 587
Tagged in : JSP-Java
0 0
Send mail
function Animal(name) {
this.name = name;
};

Animal.prototype.talk = function() {
return "";
};

function Cat(name) {
Animal.call(this, name);
};

Cat.prototype = new Animal();

Cat.prototype.talk = function() {
return "Meow!";
};

function Dog(name) {
Animal.call(this, name);
};

Dog.prototype = new Animal();

Dog.prototype.talk = function() {
return "Arf! Arf!";
};

var animals = [
new Cat("Missy"),
new Cat("Mr. Mistoffelees"),
new Dog("Lassie")
];

// prints the following:
//
// Missy: Meow!
// Mr. Mistoffelees: Meow!
// Lassie: Arf! Arf!

for (var i=0; i document.write(animals[i].name + ": " + animals[i].talk() + "
");
}


By gowtham, On - 2010-02-15



    Login to add Comments .