/** * Fail Konstr2.java * @author Jaanus Poial * @version 0.5 kevad 99 */ //================================================= // Na"ide konstruktorite u"ledefineerimisest // Eesma"rk: iga asi on kirjas u"hekordselt //================================================= class Konstr2 { // pohiprogramm silumiseks static public void main (String[] argumendid) { System.out.println (new Loom () ); System.out.println (new Loom ("Patu") ); System.out.println (new Loom (3) ); System.out.println (new Loom ("Miisu", 5) ); System.out.println (new Koer () ); System.out.println (new Koer ("Muri") ); System.out.println (new Koer ("Muki", 2) ); System.out.println (new Koer ("Sultan", 6, "Rotu") ); System.out.println (new Koer (10) ); System.out.println (new Koer (8, "Dobermann") ); System.out.println (new Koer ("Feti", "Kolli") ); } //main lopp } //Konstr2 lopp class Loom { //u"lemklass String nimi; int vanus; Loom () { // Vaikekonstruktor // Teeme nii, et k6ik po"o"rdumised la"hevad siit la"bi, // siis piisab edaspidi AINULT selle koha muutmisest paneNimi (null); paneVanus (-1); } Loom (String s) { this(); paneNimi (s); } Loom (int i) { this(); paneVanus (i); } Loom (String s, int i) { this (s); paneVanus (i); } public String votaNimi() { return nimi; } public void paneNimi (String s) { nimi = s; } public int votaVanus() { return vanus; } public void paneVanus (int i) { vanus = i; } public String toString() { //katame yle return "Olen " + getClass().getName() + ((votaNimi() == null) ? "" : " " + votaNimi()) + ((votaVanus() == -1) ? "" : ", minu vanus on " + String.valueOf (votaVanus())); } } // Loom lopp class Koer extends Loom { // alamklass String toug = "krants"; Koer() { // Vaikekonstruktor } Koer (String s) { super (s); } Koer (String s, int i) { super (s, i); } Koer (String s, int i, String t) { super (s, i); paneToug (t); } Koer (int i) { super (i); } Koer (int i, String t) { super (i); paneToug (t); } Koer (String s, String t) { super (s); paneToug (t); } public String votaToug() { return toug; } public void paneToug (String t) { toug = t; } public String toString() { //katame yle return super.toString() + ", to~u poolest " + votaToug(); } } // Koer lopp //faili lopp