Dashboard > BOO > ... > Language Guide > Classes
Classes Log In | Sign Up   View a printable version of the current page.

Added by dholton , last edited by Rodrigo B. de Oliveira on Aug 19, 2005  (view change)
Labels: 
(None)

Here's an example illustrating some of the basics about classes.

Until more documentation is here, for examples of using classes, see the classes-*.boo files under tests/testcases/integration, as well as super-*.boo, abstract-*.boo, interfaces-*.boo, baseclass-*.boo, innerclasses-*.boo, fields-*.boo, and properties-*.boo.

interface IAnimal:
    Name as string:
        get

    Legs as int:
        get

    def Eat(food)

class Dog(IAnimal):
    Name:
        get:
            return "Canine"

    Legs:
        get:
            return 4

    def Eat(food):
         if food isa IPlant:
                Speak()

    def Speak():
         print "bark!"

interface IPlant:
    pass

class Rice(IPlant):
    pass

//////////////////////////

d = Dog()

print "${d.Name} has ${d.Legs} legs."

r = Rice()
d.Eat(r)
Site running on a free Atlassian Confluence Open Source Project License granted to The Codehaus. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.2 Build:#919 Nov 26, 2007) - Bug/feature request - Contact Administrators