JAVA多态成员特性

public class DuoTaiDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Fu fu = new Zi();
		fu.method();
		fu.method2();
		fu.method4();
		//fu.method3();
		System.out.println(fu.num);
		System.out.println();
		
		Zi zi = new Zi();
		zi.method();
		zi.method2();
		zi.method3();
		zi.method4();
		System.out.println(zi.num);
	}
}

abstract class Fu{
	int num = 5;
	void method(){
		System.out.println("fu method");
	}
	void method2(){
		System.out.println("fu method2");
	}
	static void method4(){
		System.out.println("fu method4");
	}
}
class Zi extends Fu{
	int num = 8;
	void method(){
		System.out.println("zi method");
	}
	void method3(){
		System.out.println("zi method3");
	}
	static void method4(){
		System.out.println("zi method4");
	}
}


zi method
fu method2
fu method4
5


zi method
fu method2
zi method3
zi method4
8



你可能感兴趣的:(JAVA多态成员特性)