Skip to content

Instantly share code, notes, and snippets.

@joshthecoder
Created January 27, 2010 03:29
Show Gist options
  • Save joshthecoder/287513 to your computer and use it in GitHub Desktop.
Save joshthecoder/287513 to your computer and use it in GitHub Desktop.
Animal: class {
eat: func -> String { return "eating stuff" }
}
Bird: class extends Animal {
eat: func -> String { return "eating worms" }
}
main: func () {
bird := Bird new()
animal := bird as Animal
"The bird is %s" format(bird eat()) println()
"The animal is %s" format(animal eat()) println()
}
The bird is eating worms
The animal is eating stuff
The bird is eating worms
The animal is eating worms
#include <iostream>
using namespace std;
class Animal
{
public:
void Eat()
{
cout << "Eating stuff" << endl;
}
};
class Bird : public Animal
{
public:
void Eat()
{
cout << "Eating worms" << endl;
}
};
int main()
{
Bird* b = new Bird;
b->Eat();
Animal* a = (Animal*)b;
a->Eat();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment