According to this answer i tried to implement it like this
Abstract class (Pilot):
public abstract class Pilot{
abstract void fly();
}
Interface (Safety Officer):
public interface ISafetyOfficer {
void controlSafety();
}
Child class:
public class C141 extends Pilot implements ISafetyOfficer{
void fly(){
System.out.println("I'm flying C-141.");
}
public void controlSafety(){
System.out.println("I'm control safety.");
}
and in main()
of Main class that cannot call controlSafety()
method
public class Main {
public static void main(String[] args) {
Pilot pilot = new C141();
pilot.fly();
pilot.controlSafety(); // Cannot call controlSafty here.
}
}
The problem occurred in function main()
. Can anyone tell me why i can't call controlSafety()
method in OOP way.