Read the code carefully before you run it.
class Customer {
var name: String = ""
}
fun main() {
val customer1 = Customer()
customer1.name = "Anna"
val customer2 = customer1
customer2.name = "Ben"
println("${customer1.name} ${customer2.name}")
}
What does the code print? Does customer1 change even though only customer2.name is modified — just as with `var b = a` (Int), where only b changes and not a?
Define a class Product with two mutable properties: name of type String (initial value "") and price of type Double (initial value 0.0). Add a method showInfo() that prints "Product: <name>, price: <price>€". In main(), create a product, set name to "Keyboard" and price to 49.99, and call showInfo().
Before you get a hint: what have you tried, and where exactly are you stuck?
1. What is the difference between a class and an object?
2. Two variables a and b point to the same object after val b = a. What happens when you change a property through b?