/** * Fail Loomad.java * @author Jaanus Poial * @version 0.2 kevad 99 */ //================================================= // Na"ide pa"rimisest ja meetodite u"lekatmisest //================================================= class Loomad { // pohiprogramm static public void main (String[] argumendid) { System.out.println ("Mida loomad ytlevad?"); Loom minuLoom = new Loom ("Patu"); System.out.println (minuLoom); //kasutab toString() meetodit Kass minuKass = new Kass ("Kiti"); System.out.println (minuKass); minuLoom = minuKass; System.out.println (minuLoom); Koer minuKoer = new Koer ("Muri"); System.out.println (minuKoer); } //main lopp } //Loomad lopp class Loom { String nimi; Loom (String s) { //konstruktor paneNimi (s); } public String votaNimi() { return nimi; } public void paneNimi (String s) { nimi = s; } public String toString() { //katame yle return "Olen loom " + votaNimi(); } } // Loom lopp class Kass extends Loom { //alamklass int vurrupikkus; Kass (String s) { super (s); } public String toString() { //katame kaetu veel yle return "Olen KASS " + votaNimi(); } } // Kass lopp class Koer extends Loom { //teine alamklass boolean sabaga; Koer (String s) { super (s); sabaga = true; } } // Koer lopp //faili lopp