Aan de slagGa gratis aan de slag

Creating methods in interfaces

Tesla cars have a unique self-driving mode feature that allows drivers to sit back and relax while the car drives itself. In the Tesla class, you will implement the self-driving features of Tesla cars using an interface, but first, you will need to create the interface for this self-driving ability.

NOTE: Non-concrete methods created inside interfaces are abstract by default.

Deze oefening maakt deel uit van de cursus

Introduction to Object-Oriented Programming in Java

Cursus bekijken

Oefeninstructies

  • Create an interface ElectricCar inside the Main class.
  • Add a void method, activateSelfDriving, in the ElectricCar interface.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

public class Main {
    
    // Create ElectricCar interface with activateSelfDriving method
    ____ ____ {
    
        ____ ____();
    }      
    
    static class Tesla {                                      
           
    }

    public static void main(String[] args) {
       
    }
}
Code bewerken en uitvoeren