Skip to content

Instantly share code, notes, and snippets.

@bruceharris
Created July 3, 2013 16:14
Show Gist options
  • Save bruceharris/5919946 to your computer and use it in GitHub Desktop.
Save bruceharris/5919946 to your computer and use it in GitHub Desktop.
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