Run the following Groovy program. The instance variable "success" changes value between the end of the second constructor and the end of the first constructor. This program works as expected in Java.
class Pinger {
boolean success
Pinger(String destHost) {
this(destHost, 1, 100)
println "at end of little constructor, success is type ${success.class} a\
nd value ${success}"
}
Pinger(String destHost, int in_n, int in_hops) {
success = true
println "at end of constructor, success is type ${success.class} and valu\
e ${success}"
}
}
Pinger p = new Pinger("www.yahoo.com")
println "Success is ${p.success}"
groovy> class Pinger { groovy> boolean success groovy> Pinger(String destHost) { groovy> this(destHost, 1, 100) groovy> println "at end of little constructor, success is type ${success.class} and value ${success}" groovy> } groovy> Pinger(String destHost, int in_n, int in_hops) { groovy> success = true groovy> println "at end of constructor, success is type ${success.class} and value ${success}" groovy> } groovy> } groovy> Pinger p = new Pinger("www.yahoo.com") groovy> println "Success is ${p.success}" at end of constructor, success is type class java.lang.Boolean and value true at end of little constructor, success is type class java.lang.Boolean and value true Success is trueseems like its working now