hi all ..
plzzzz...I am novice in Java and I have some queries about some programs that my teacher give them to us.. so I need ur help ..
Program 1:
// prints the following: // // Missy: Meowww! // Garfield: Meowww! // Lassie: Arf! Arf! // interface Animal { String getName(); String talk(); } abstract class AnimalBase implements Animal { private final String name; protected AnimalBase(String name) { this.name = name; } public String getName() { return name; } } class Cat extends AnimalBase { public Cat(String name) { super(name); } public String talk() { return "Meowww!"; } } class Dog extends AnimalBase { public Dog(String name) { super(name); } public String talk() { return "Arf! Arf!"; } } public class TestAnimals { public static void main(String[] args) { Animal[] animals = { new Cat("Missy"), new Cat("Mr. Mistoffelees"), new Dog("Lassie") }; for (Animal a : animals) { System.out.println(a.getName() + ": " + a.talk()); } } }
here..why she use " final "?private final String name;
protected AnimalBase(String name) { this.name = name; }
What is the benefit of " this. " ?
and also why she use "protected" and what is the benefit of it ?
for (Animal a : animals)
why she use this "for" and what is the benefit of it ?
thanx a lot ..and plz I want the answers at nearest time