Groovy web console

subscribe to the feed Subscribe
to this
site
Groovy inner class (via #groovywebconsole)
tweet this snippet Tweet
this
script

Groovy inner class

Published 2 years ago by John Bito with tags inner class
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class Dog {
    def color, bark
    class Bark {
        def pitch, volume
        Bark(p, v) {
            pitch = p
            volume = v
        }
    }
    Dog(c) {
        color = c
        bark = new Bark(this, "low", "loud")
    }
    String toString() {
        return "The $color dog barks ${bark.pitch} and ${bark.volume}"
    }
}

println new Dog("yellow")