/Main.java Secret
Created
February 13, 2016 16:28
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
import java.lang.System; | |
public class Main { | |
public static void main(String[] args) { | |
Foo element1 = new Foo("1Foo"); | |
Foo element2 = new Foo("2Foo"); | |
Foo element3 = new Foo("3Foo"); | |
Foo element4 = new Foo("4Foo"); | |
Foo element5 = new Foo("5Foo"); | |
Foo[] data = new Foo[] { | |
element1, element2, element3, element4, element5 | |
}; | |
for (int i = 0; i < data.length; i++) | |
System.out.println(data[i].getID()); | |
for (int i = 0; i < data.length; i++) | |
data[i] = new Bar(data[i]); | |
for (int i = 0; i < data.length; i++) | |
System.out.println(data[i].getID()); | |
System.out.println(element1.getID()); | |
} | |
public static class Foo { | |
private String ident; | |
public Foo(String id) { | |
this.ident = id; | |
} | |
public String getID() { | |
return this.ident; | |
} | |
} | |
public static class Bar extends Foo { | |
public Bar(String id) { | |
super(id); | |
} | |
public Bar(Foo foo) { | |
super(foo.getID()); | |
} | |
@Override | |
public String getID() { | |
return super.getID() + "Bar"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment