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();
}