I do potih assignments from Reshebnik and it is on the third point I was knocked out of a rut.
Create a class object Kitten using classes Animal, Cat. Methods:
display the name on the console
give voice
- give birth to offspring (create your own kind).
public class Main { public static void main(String[] args) { Cat cat = new Cat(); Kitten kitten = cat.giveBirth(); System.out.println(kitten); cat.printName(); } } interface Mother { <T extends Animal> Kitten giveBirth(); } abstract class Animal { protected String name; abstract void say(); public void printName() { System.out.printf("My name is %s\n", name); } } class Cat extends Animal implements Mother { public Cat() { name = "Cat"; } @Override public <T extends Animal> Kitten giveBirth() { return new Kitten(); } @Override public void say() { System.out.printf("Meow\n"); } } class Kitten extends Animal { public Kitten() { name = "Kitten"; } @Override public void say() { System.out.printf("Meow\n"); } } How to make it work from the output in main, that is, something like this:
public class Main { public static void main(String[] args) { Cat cat = new Cat("nameCat"); cat.say(); System.out.printf(cat.giveBirth()); Cat catTwo = new Cat("nameCatTwo"); catTwo.say(); System.out.printf(catTwo.giveBirth()); } } And did I understand the third point? What should he output? Almost 6 am, I do not understand anything. And how to correctly override for each class the methods equals() , hashCode() , toString() ?