Watch This Video
https://groovy-lang.org/operators.html#Operator-Overloading
def a=10
def b=20
println a+b
println a.plus(b)
def s1="Hello"
def s2="world"
println s1+s2
println s1.plus(s2)
class Account{
BigDecimal balance
Account plus(Account other){
new Account(balance:this.balance+other.balance
}
String toString(){
"Account Balance: $balance"
}
}
Account savings=new Account(balance:500)
Account checkings= new Account(balance:100)
println savings+checkings
No comments:
Post a Comment
Note: only a member of this blog may post a comment.