Java 8.2


interface Interface{
	
}
class Father{
	public Father() {
		
	}
	protected <T> void pln(T sT) {
		System.out.println(sT);
	}
	public void F1() {
		pln(this);
	}
	protected void F2() {
		pln(this);
	}
	private void F3() {
		
	}
}
class Son1 extends Father{
	private int Spp;
	
	@Override
	protected void F2() {
		// TODO 自动生成的方法存根
		super.F2();
	}
	@Override
	public void F1() {
		// TODO 自动生成的方法存根
		this.F2();
	}
}
public class Mine {
	public static void main(String[] args) {
		Father father = new Father();
		Son1 son1 = new Son1();
		father.F1();
		son1.F1();
	}
}

output:
image
可以看见尽管son调用的是father的成员 但是这个this识别的仍然是son类型


class Kitauji{
	static int cnt = 0;
	
	public Kitauji() {
		cnt ++ ;
		System.out.println(this);
	}
	@Override
	public String toString() {
		return "Class: [Kitauji] No." + cnt;
	}
}
public class Mine{
	public static void main(String[] args) {
		Kitauji[] sKitauji = new Kitauji[5];
		for(int i = 0;i < sKitauji.length; i++) {
			Kitauji d = new Kitauji();
			sKitauji[i] = d;
		}
	}
}
posted @ 2023-08-02 21:14  N0zoM1z0  阅读(2)  评论(0编辑  收藏  举报