groovy-lecture/assignments/solutions/konstruktor.groovy

17 lines
324 B
Groovy
Raw Normal View History

2024-06-09 20:55:46 +02:00
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()