`
dannyhz
  • 浏览: 368091 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

临时实现 面对接口 抽象方法 基类继承方法

阅读更多

1. 光只有接口的临时实现
public interface IntTest {
	public String getABC();
}


public class InheritIntTest {
	public static void main(String[] args) {
		
		
		IntTest it = new IntTest(){
			public String getABC() {
				
				return "123";
			}
		};
		
		System.out.println(it.getABC());
		
		
	}
}


2. 抽象方法临时具体实现
public abstract class AbstractABC {
	public abstract String getABC();
	
	public static void main(String[] args) {
		AbstractABC abc = new AbstractABC(){

			@Override
			public String getABC() {
				return "123";
			}
			
		};
		
		System.out.println(abc.getABC());
	} 
	
}

3. 从继承类的保护方法再临时实现


public class ProtectBaseClass {
	protected String getAbc(){
		return "456";
	};
	
	public static void main(String[] args) {
		InheritBase ib = new InheritBase(){
			public String getAbc(){
				return "123";
			}
		};
		
		System.out.println(ib.getAbc());
	}
}

class InheritBase extends ProtectBaseClass{

	
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics