Created
January 10, 2013 09:16
-
-
Save cyrilmottier/4500676 to your computer and use it in GitHub Desktop.
Java puzzle: field instantiation
This file contains 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 com.cyrilmottier.test; | |
public class ClassA { | |
public ClassA() { | |
System.out.println("ClassA()"); | |
method(); | |
} | |
public void method() { | |
System.out.println("ClassA.method()"); | |
} | |
} |
This file contains 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 com.cyrilmottier.test; | |
public class ClassB extends ClassA { | |
private static final Point POINT = new Point(0, 0); | |
private final String mString = "Hello world"; | |
private final Point mPoint = new Point(1, 1); | |
public ClassB() { | |
super(); | |
System.out.println("ClassB(): " + POINT + " / " + mString + " / " + mPoint); | |
} | |
@Override | |
public void method() { | |
System.out.println("ClassB.method(): " + POINT + " / " + mString + " / " + mPoint); | |
super.method(); | |
} | |
public static void main(String[] args) { | |
new ClassB(); | |
} | |
} |
This file contains 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 com.cyrilmottier.test; | |
public class Point { | |
public final int x; | |
public final int y; | |
public Point(int x, int y) { | |
this.x = x; | |
this.y = y; | |
} | |
@Override | |
public String toString() { | |
return "Point(" + x + ", " + y + ")"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment