|
|
polymorphism in java - JSP/Java
|
Views : 587
|
|
Tagged in : JSP-Java
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
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 |
|
|
|