Exercise: Simulating a Pizza Factory
Enhance your Kotlin proficiency by creating a companion object within a class for creating instances with specific characteristics.
We'll cover the following
Problem statement
Define a companion
object in the Pizza
class that will contain factory functions for creating pizzas. The functions should be named hawaiian
and margherita
and should return pizzas with the following toppings:
Hawaiian:am, pineapple
Margherita:omato, mozzarella
Tip: To create a list of strings, you can use the listOf
function. For example, listOf("a", "b", "c")
creates a list with three elements: "a"
, "b"
, and "c"
.
The actual output when running the provided code should be as follows:
Get hands-on with 1400+ tech skills courses.