Created
July 3, 2013 16:14
-
-
Save bruceharris/5919946 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 net.bruceharris.test.inheritance; | |
import static org.junit.Assert.assertEquals; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class InheritanceTest { | |
private Child c = new Child(); | |
private Parent p = new Parent(); | |
@Test | |
public void testStuff() { | |
assertEquals("Child's getI should get parent field", 1, c.getI()); | |
assertEquals("Child should have 2 different instance field with same name - getI() should be 1", | |
1, c.getI()); | |
assertEquals("Child should have 2 different instance field with same name - getChildI() should be 2", | |
2, c.getChildI()); | |
} | |
private static class Parent { | |
private int i = 1; | |
public int getI() { | |
return i; | |
} | |
public void setI(int i) { | |
this.i = i; | |
} | |
} | |
private static class Child extends Parent { | |
private int i = 2; | |
public int getChildI() { | |
return i; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment