一小段代码:父类和子类
父類:
public class Father {
public void function1(){
?? System.out.println("this is father's function 1");
}
public void function2(){
?? System.out.println("this is father's function 2");
}
public void function3(){
?? System.out.println("this is father's function 3");
}
public void function(){
?? function1();
?? function2();
?? function3();
}
}
子類:
public class Son extends Father {
public void function3(){
?? System.out.println("this is son's function 3");
}
}
測試父類:
public class TestFather extends TestCase {
Father f;
@Before
protected void setUp() throws Exception {
?? f=new Father();
}
@Test
public void testFunction() {
?? f.function();
}
}
輸出:
this is father's function 1
this is father's function 2
this is father's function 3
測試子類:
public class TestSon {
Son s;
@Before
public void setUp() throws Exception {
?? s=new Son();
}
@Test
public void testFunction() {
?? s.function();
}
}
輸出:
this is father's function 1
this is father's function 2
this is son's function 3
?
這樣的一個結果,對我是有用的~~~
轉載于:https://blog.51cto.com/winters1224/799086
總結
以上是生活随笔為你收集整理的一小段代码:父类和子类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: fieldset在ie8下的margin
- 下一篇: POJ-1436 线段树 区间更新