欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java多态

程序员文章站 2022-07-12 14:46:36
...
package day20161008;

class BaseClass {
	
	public int book = 6;
	
	public void base() {
		System.out.println("father base");
	}
	
	public void test() {
		System.out.println("father test");
	}
}

public class TestsubClass extends BaseClass{

	public String  book = "book";
	
	public void base() {
		System.out.println("son base");
	}
	
	public void sub() {
		System.out.println("son sub");
	}
	
	public static void main(String[] args ){
		
		BaseClass baseClass = new BaseClass();
		System.out.println(baseClass.book);
		baseClass.base();
		baseClass.test();
		
		TestsubClass testsubClass = new TestsubClass();
		System.out.println(testsubClass.book);
		testsubClass.base();
		testsubClass.test();
		testsubClass.sub();
		
        BaseClass ploymophicBc = new TestsubClass();  
        System.out.println(ploymophicBc.book);  
        ploymophicBc.base();  
        ploymophicBc.test(); 

	}
	
}

/*6
father base
father test
book
son base
father test
son sub
6
son base
father test*/

 

来源:http://cakin24.iteye.com/blog/2327956

 

 

相关标签: 多态