Created
August 18, 2013 00:41
-
-
Save nmaier/6259373 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
package nmaier.so_der; | |
public class Program { | |
static class Piece {} | |
static class Man extends Piece{} | |
static class Square { | |
private Piece p_; | |
public Square(Piece p) { | |
p_ = p; | |
} | |
public Piece getPiece() { | |
return p_; | |
} | |
} | |
static void print(Piece piece) { | |
System.out.println("Piece"); | |
} | |
static void print(Man man) { | |
System.out.println("Man"); | |
} | |
static void print(Square square) { | |
print(square.getPiece()); | |
} | |
public static void main(String [] args) { | |
Square s = new Square(new Man()); | |
print(s); // Prints "Piece" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment