groovy-lecture/assignments/solutions/konstruktor.groovy

17 lines
324 B
Groovy

class Person {
String name
int age
Person(String name, int age) {
this.name = name
this.age = age
}
def introduce() {
println("Hello, my name is ${name} and I am ${age} years old.")
}
}
// Verwendung der Klasse Person
def person = new Person("Alice", 30)
person.introduce()