You are designing a car simulation game using JavaScript. Each type of car (e.g., sedan, truck, etc.) has different methods for calculating fuel efficiency. Which object-oriented programming concept would be most appropriate to ensure that each car type can calculate fuel efficiency in its own way, while still inheriting basic characteristics from a general Car class?
- Inheritance
- Polymorphism
- Encapsulation
- Abstraction
Polymorphism allows different car types (e.g., sedan, truck) to have their own implementations of the fuel efficiency calculation method while inheriting common attributes and behaviors from the general Car class. This ensures flexibility and extensibility in your game.
Loading...
Related Quiz
- Unlike traditional functions, arrow functions do not have their own __________.
- What is the result of the comparison operator === if the operands are of different types?
- How can you create a new Promise?
- The ________ method is used to parse a JSON string into a JavaScript object.
- You're developing a game and you're using a two-dimensional array to represent a grid of game cells. How could you access the third cell in the second row of a grid defined as const grid = [[1,2,3], [4,5,6], [7,8,9]]?