Saturday, October 3, 2015

Groovy scripting: Class

Bank.log=log
log.info("Hello World!")
Bank obj1 = new Bank()
Bank obj2 = new Bank()

obj1.accountnumber=1235
obj1.accounttype="Savings"
obj2.accountnumber=54321
obj2.accounttype="Current"

//log.info obj1.accountnumber + " " + obj1.accounttype
//log.info obj2.accountnumber + "  " + obj2.accounttype
log.info obj1.printaccount()



class Bank{

def static log
def accountnumber
def accounttype

public void printaccount(){
log.info("Your account type is $accounttype and number is $accountnumber")
}
}


Output:

Sat Oct 03 15:54:38 IST 2015:INFO:Hello World!
Sat Oct 03 15:54:38 IST 2015:INFO:Your account type is Savings and number is 1235
Sat Oct 03 15:54:38 IST 2015:INFO:null

No comments:

Post a Comment