Skip to content

Instantly share code, notes, and snippets.

@kamatama41
Created July 29, 2012 14:43
Show Gist options
  • Save kamatama41/3199313 to your computer and use it in GitHub Desktop.
Save kamatama41/3199313 to your computer and use it in GitHub Desktop.
OrverrideConstructorTest
package com.kamatama41.sandbox4j;
import org.junit.Test;
public class OrverrideConstructorTest {
@Test(expected=NullPointerException.class)
public void test_Aの初期化時にBのsomeMethodが呼ばれてぬるぽ発生() throws Exception {
new OrverrideConstructorTest().new B();
}
class A {
A() {
System.out.println("Construntor of A");
someMethod();
}
void someMethod() {
System.out.println("Call someMethod of A");
}
}
class B extends A {
C c;
B() {
System.out.println("Construntor of B");
c = new C();
}
@Override
void someMethod() {
System.out.println("Call someMethod of B");
c.doSomething();
}
}
class C {
void doSomething() {
System.out.println("test");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment