6.6. Access Control

 

 

解读 6.6.2.2. Qualified Access to a protected Constructor

https://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#jls-6.6 

package com.test01;
public class C {
	protected C() {

	}
}

 

package com.test01;
public class K{
	public class C{
		protected C(){
			
		}
	}
}

对protected修饰符的构造函数进行Access测试:  

package com.test02;

import com.test01.K;
import com.test01.C;

public class Test {
	
	class S1 extends K.C{
		S1(K k){
			k.super();
		}
	}
	
	class S2{
		public void t(){
			// new K().new C(); // 报错
			new K().new C(){};
		}
	}
	
	class S3 extends C{
		S3(){
			super();
		}
	}
	
	class S4{
		public void t(){
			// new C(); // 报错
			new C(){};
		}
	}
}

  

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(6.6. Access Control)