interface Foo1
{
int bar();
}
class Sprite
{
public int fubar( Foo1 foo )
{
return foo.bar();
}
public void testFoo()
{
fubar(
new Foo1()
{
public int bar()
{
return 1;
}
}
);
}
}
无法理解 fubar() 方法。有人可以解释一下这个程序吗
最佳答案
因此,根据您的代码,您有一个名为 Foo1 的接口(interface),其中包含一个名为 bar()
的抽象方法。
Sprite类有两个方法fubar和testFoo。
在您的 fubar 方法中,它获取 Foo1 对象作为参数并返回 foo.bar()
值。
在您的 testFoo 方法中,您正在调用 fubar 方法,并在其中实现抽象 bar()
方法,该方法返回 1 作为整数值。
您的代码中仍然没有 main 方法,因此还没有输出。
这是您的代码的概述,如果您需要更多说明,请告知。
关于java - 有人可以解释一下这段代码中发生了什么吗?无法理解简单的oops程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29230342/