Java i can not initalize reference varibale in subclass because "VariableDeclaratorId expected after this token"

25 Views Asked by At

I have created an interface Flyable and the class FlyableWithWing implementing this interface

public interface Flyable {
    void fly();
}
public class FlyWithWings implements Flyable {
    @Override
    public void fly() {
        System.out.println("This animal flyies with wings");
    }
}

I have created a supers class Duck and subclass MallarDuck. Class Duck holds a reference to an object type Flyable.

public class Duck {
    Flyable flyBehaviour;

    void perfomFly() {
        flyBehaviour.fly();
    }
}

I tried to initilize varibale flyBehaviour in subclass MallarDuck with Flyable object. but i get an error "VariableDeclaratorId expected after this token".

public class MallarDuck extends Duck {
    flyBehaviour = new FlyWithWings();
}
0

There are 0 best solutions below