抽象类的实例化
2015-12-10 10:18
197 查看
eg:
public abstract class Base {
public Base(int i){
System.out.println("Base constructor.i="+i);
}
public abstract void f();
}
public class AnonymousConstructor {
public static Base getBase(int i){
return new Base(i){
public void f(){
System.out.println("In anonymous f()");
}
};
}
public static void main(String[] args) {
Base base = getBase(47);
base.f();
[error:
Base b = new Base(2);//Cannot instantiate the type Base]
}
}
result:
Base constructor.i=47
In anonymous f()
public abstract class Base {
public Base(int i){
System.out.println("Base constructor.i="+i);
}
public abstract void f();
}
public class AnonymousConstructor {
public static Base getBase(int i){
return new Base(i){
public void f(){
System.out.println("In anonymous f()");
}
};
}
public static void main(String[] args) {
Base base = getBase(47);
base.f();
[error:
Base b = new Base(2);//Cannot instantiate the type Base]
}
}
result:
Base constructor.i=47
In anonymous f()
相关文章推荐
- sql模糊查询
- Android中插件开发篇之----应用换肤原理解析
- Android开发--RecyclerView使用,看AndroidL新特性,android5.0新特性
- myibatis dao接口无需写实现类
- servlet学习笔记01基本概念
- qsetting读取ini文件
- How to console into your devices
- 获得ios屏幕宽度
- Objective-c之Associative
- What's NoSQL
- TFS 2010:服务器不提供Team Foundation服务,HTTP代码503,Service Unavailable
- C# from子句使用问题
- 防止中断后系统调用重启动的signal函数。
- .CN域名总量约1500万:11月净增193万 增速加快
- shodan使用笔记
- saxbuilder用法
- android点击两次返回键实现程序退出
- iOS 修改导航栏的返回按钮的内容
- HTTP Status 500 - Error instantiating servlet class
- Protocol Buffers代替JSON 的五个原因