public class Parcel6 { public Contents cont() { return new Contents() { private int i = 11; public int value() { return i; } }; // Semicolon required in this case } public static void main(String[] args) { Parcel6 p = new Parcel6(); Contents c = p.cont(); } } ///:~cont()方法同时合并了返回值的创建代码,以及用于表示那个返回值的类。除此以外,这个类是匿名的——它没有名字。 return new Contents()返回一个没有名称的内部类(匿名内部类)
public class A { public A() { JButton but = new JButton("a"); but.addActionListener( new MyAction() //匿名类部类。 { public void actionPerformed(ActionEvent evt) { } } ); }
class B //内部类 { } }//刚写出来的,有可能有错。。 //书上都说得很清楚呀,一个一个的搞定就是了。。 呵呵。。
你要别人在CSDN帮你写书吗?
public Contents cont() {
return new Contents() {
private int i = 11;
public int value() { return i; }
}; // Semicolon required in this case
}
public static void main(String[] args) {
Parcel6 p = new Parcel6();
Contents c = p.cont();
}
} ///:~cont()方法同时合并了返回值的创建代码,以及用于表示那个返回值的类。除此以外,这个类是匿名的——它没有名字。
return new Contents()返回一个没有名称的内部类(匿名内部类)
public class A
{
public A()
{
JButton but = new JButton("a");
but.addActionListener( new MyAction() //匿名类部类。
{
public void actionPerformed(ActionEvent evt)
{
}
}
);
}
class B //内部类
{
}
}//刚写出来的,有可能有错。。
//书上都说得很清楚呀,一个一个的搞定就是了。。 呵呵。。