Created
January 27, 2010 03:29
-
-
Save joshthecoder/287513 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The bird is eating worms | |
The animal is eating stuff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The bird is eating worms | |
The animal is eating worms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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