public class Solution {
public static void main(String[] args) {
Pet pet = new Cat();
System.out.println(pet.getName());
}
public static class Pet {
public String getName() {
return "Ich bin Fluffy";
}
}
public static class Cat extends Pet {
public String getName(){
return "Ich bin eine Katze";
}
}
}
hidden #10625598
Level 23
was müsste ich hier machen um ich bin fluffy auszugeben?
Gelöst
Kommentare (2)
- Beliebt
- Neu
- Alt
Du musst angemeldet sein, um einen Kommentar schreiben zu können
Corina Bodea
1 Juni 2020, 19:25
Hey!
According to 4th requirement you must create a setName function inside Pet which will be overriden inside Cat class.
Like:
Finally, in main you should have:
Prost! 0
hidden #10625598
1 Juni 2020, 19:38
okay okay interesting! thanks! so thats the way to go right, you simply call it up separatley like this, is there a more convenient way? :D
public static void main(String[] args) {
Pet pet = new Cat();
pet.setName("Ich bin Fluffy");
System.out.println(pet.getName());
pet.setName("Ich bin eine Katze");
System.out.println(pet.getName());
}
public static class Pet {
public String name;
public String getName() {
return name;
}
public void setName(String name){
this.name = name;
}
}
public static class Cat extends Pet {
public String name;
public String getName() {
return name;
}
public void setName(String name){
this.name = name;
}
}
0