Implementing interface on Tesla class
To make the Tesla
class have the self-driving feature, you will use the ElectricCar
interface to enable this feature. In the Tesla
class, you will harness the interface and implement the self-driving method as a requirement.
NOTE: Interface non-void methods must be implemented in the class implementing the interface.
Este exercício faz parte do curso
Introduction to Object-Oriented Programming in Java
Instruções do exercício
- Implement the
ElectricCar
interface using theimplements
keyword on theTesla
class. - Implement the
void
activateSelfDriving
method inside theTesla
as apublic
method, and make it print out"self driving on"
when called. - Call the
activateSelfDriving
method on themyTesla
object instance.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
public class Main {
interface ElectricCar {
void activateSelfDriving();
}
// Implement ElectricCar Interface
static class Tesla ___ ___ {
// Implement activateSelfDriving method
____ ____ ____() {
____.____.____("self driving on");
}
}
public static void main(String[] args) {
Tesla myTesla = new Tesla();
// Call activateSelfDriving method
____.____();
}
}