I am creating an interface say ‘Car’
public interface Car {
public void drive(int Speed, int Gear ); // for cars which have gears
public void drive(int Speed); // for cars which do not have gears
}
Now i am creating my implimentation classes say SimpleCar and AdvanceCar where
- SimpleCar do not have gears
- AdvanceCar have gears
Now when i write my implementation classes i am forced to code for both the methods even though i do not want them in my implementation classes
public class SimpleCar implements Car {
public void drive(int Speed, int Gear ){ ... }; // dont want this method in SimpleCar
public void drive(int Speed ){ ... };
}
can someone help me design my interface which has a method but the implementation classes have different signatures?
1 Answer