Untitled
unknown
plain_text
3 years ago
2.3 kB
5
Indexable
class Animal { int Age; String Gender; Animal(int a,String g){ Age=a; Gender=g; } public String isMammal() { return " yes"; } public void mate(boolean y) { System.out.println(y); } public void voice() { System.out.println(" Animal voice is hahahha"); } final void sleep() { System.out.println("sleep"); } public String toString() { return this.getClass().getSimpleName()+" "+isMammal(); } } class Duck extends Animal { String beakcolor= "yellow"; Duck(int Age,String gender,String beakcolor){ super(Age,gender); this.beakcolor=beakcolor; } public String isMammal() { return " no"; } @Override public String toString() { return this.getClass().getSimpleName()+" "+isMammal(); } public void voice() { System.out.println("The duck voice is quack quack"); } } class Fish extends Animal { int sizeinFt; boolean caneat; Fish(int Age,String gender,int a,boolean b){ super(Age,gender); sizeinFt=a; caneat=b; } public void voice() { System.out.println("The fish voice is pshshshj"); } public String isMammal() { return " no"; } public String toString() { return this.getClass().getSimpleName()+" "+isMammal(); } } class Zebra extends Animal { boolean iswild; Zebra(int Age,String gender,boolean y){ super(Age,gender); iswild=y; } public void voice() { System.out.println("The zebra voice is whinny"); } public String isMammal() { return " yes"; } public String toString() { return this.getClass().getSimpleName()+" "+isMammal(); } } class Main { public static void main(String[] args) { Animal animal_1=new Animal(1,"male"); Animal animal_2=new Animal(2,"female"); Duck duck_1 = new Duck(2,"female","yellow"); Duck duck_2 = new Duck(3,"female","yellow"); Duck duck_3 = new Duck(4,"female","yellow"); Fish fish_1=new Fish(2,"male",2,false); Fish fish_2=new Fish(2,"male",2,true); Zebra zebra_1= new Zebra(2,"female",true); Zebra zebra_2= new Zebra(2,"male",true); Zebra zebra_3= new Zebra(2,"male",true); Zebra zebra_4= new Zebra(2,"female",true); animal_1.voice(); duck_1.voice(); fish_1.voice(); zebra_1.voice(); } }
Editor is loading...