Created
May 25, 2016 19:44
-
-
Save marcoonroad/71f5b3b53e3c5166e98a796ca6667225 to your computer and use it in GitHub Desktop.
Wat?
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 bug; | |
public class Main { | |
public static void main (String[ ] args) { | |
SuperClass a = new SuperClass ( ); // 1 | |
SubClass b = new SubClass ( ); // 2 e 1.0 | |
SuperClass c = new SuperClass ( ); // 3 | |
SubClass d = new SubClass ( ); // 4 e 2.0 | |
a.printSelf (c); // 3 | |
c.printSelf (a); // 1 | |
a.printSub (b); // 1.0 e 2 | |
a.printSub (d); // 2.0 e 4 | |
} | |
} | |
// estado é privado e inteiro | |
class SuperClass { | |
private static int serial = 0; | |
private int state; | |
private synchronized static void create (SuperClass object) { | |
serial += 1; | |
object.state = serial; | |
} | |
public SuperClass ( ) { | |
create (this); | |
} | |
public void printSelf (SuperClass object) { | |
System.out.println (object.state); | |
} | |
public void printSub (SubClass object) { | |
System.out.print (object.state + " | "); | |
printSelf ((SuperClass) object); | |
} | |
} | |
// estado é público e double | |
class SubClass extends SuperClass { | |
private static double serial = 0.0; | |
public double state; | |
private synchronized static void create (SubClass object) { | |
serial += 1; | |
object.state = serial; | |
} | |
public SubClass ( ) { | |
super ( ); | |
create (this); | |
} | |
} | |
// end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment