Interface declaration and implementation
📖 Scenario: You are creating a simple program to represent different types of vehicles. Each vehicle can start and stop. You will use an interface to define these actions and then create classes that implement this interface.
🎯 Goal: Build a Kotlin program that declares an interface called Vehicle with two functions: start() and stop(). Then create two classes, Car and Bike, that implement the Vehicle interface. Finally, create objects of these classes and call their start() and stop() functions.
📋 What You'll Learn
Declare an interface called
Vehicle with two functions: start() and stop()Create a class called
Car that implements the Vehicle interfaceCreate a class called
Bike that implements the Vehicle interfaceIn both classes, provide simple print statements inside
start() and stop() functionsCreate objects of
Car and Bike and call their start() and stop() functions💡 Why This Matters
🌍 Real World
Interfaces are used in real-world apps to define common behaviors for different objects, like vehicles, users, or devices, so they can be handled in a uniform way.
💼 Career
Understanding interfaces is important for Kotlin developers to write clean, modular, and maintainable code, especially in Android app development and backend services.
Progress0 / 4 steps