Я знаю как скомпелировать код этой задачи просто вставив методы в каждый созданный класс. Но почему не работает эта конструкция.
Можете простым языком объяснить?
package com.javarush.task.task12.task1226;
/*
Лазать, летать и бегать
*/
public class Solution {
public static void main(String[] args) {
}
public interface CanFly {
void fly();
}
public interface CanClimb {
void climb();
}
public interface CanRun {
void run();
}
public class Cat implements CanClimb, CanRun {
Cat cat = new Cat();
cat.climb()
{
System.out.println("F");
}
cat.run()
{
System.out.println("A");
}
}
public class Dog implements CanRun {
Dog dog = new Dog();
dog.run()
{
System.out.println("A");
}
}
public class Tiger extends Cat {
Cat tigrenok = new Tiger();
tigrenok.climb()
{
System.out.println("F");
}
tigrenok.run()
{
System.out.println("A");
}
}
public class Duck implements CanClimb, CanRun, CanFly {
Duck utka = new Duck;
utka.climb()
{
System.out.println("F");
}
utka.run()
{
System.out.println("A");
}
utka.fly()
{
System.out.println("M");
}
}
}