黑马程序员技术交流社区
标题:
内部类问题!
[打印本页]
作者:
赵家阳
时间:
2012-9-22 18:21
标题:
内部类问题!
本帖最后由 赵家阳 于 2012-9-22 18:23 编辑
abstract class Inter{
void method(){
}
abstract void print();
}
class Test{
/**
* //补足代码,通过匿名内部类。
* @return
*/
/**
* 问题一:如下声明,总提示这样一个错误:The type Inter cannot be a superinterface of function; a superinterface must be an interface
* 请问这是什么意思??该怎么解决??
*/
static class function implements Inter{
//提示如下:怎么解决?
//The type Oi cannot be a superinterface of function;
//a superinterface must be an interface
void print(){
System.out.println();
}
}
public static Inter function(){ //This method must return a result of type Oi
/**
* 因为return的是一个Oi对象类型的,所以此处要定义成一个返回OI类型的函数
*/
return new Inter(){
public void print(){
}
void method(){
}
};
}
}
public class InnerClassTest {
public static void main(String[] args){
/**
* 根据下句代码补全上面的代码
*/
Test.function().method();
/*
* 语句分析:首先,这是一个类名调用,因此,Test类里面有一个function方法,且function()方法是静态的
* .method():function这个方法运算后的结果是一个对象,而且是一个Inter类型的对象
*/
/**
* 问题2:.method():function这个方法运算后的结果是一个对象,而且是一个Inter类型的对象,为什么??
*/
}
}
复制代码
代码中有两个问题,在此不方便说,只能在代码中叙述,请高手给看看!谢谢!
/**
* 问题一:如下声明,总提示这样一个错误:The type Inter cannot be a superinterface of function; a superinterface must be an interface
* 请问这是什么意思??该怎么解决??
*/
/**
* 问题2:.method():function这个方法运算后的结果是一个对象,而且是一个Inter类型的对象,为什么??
*/
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2