class Person(val name: String, val age: Int) object Person { // Factory method to create a Person instance with default age def createWithName(name: String): Person = new Person(name, 0) // Factory method to create a Person instance with specified age def createWithNameAndAge(name: String, age: Int): Person = new Person(name, age) } object Main extends App { // Using the factory methods val person1 = Person.createWithName("Alice") val person2 = Person.createWithNameAndAge("Bob", 30) println(s"Person 1: ${person1.name}, ${person1.age}") println(s"Person 2: ${person2.name}, ${person2.age}") }