20240321_01_InnerClass
Test类1
package InnerClass;
public class Test {
public static void main(String[] args) {
Animals a = new Animals(){
@Override
public void cry() {
System.out.println("a cat meow.");
}
};
a.cry();
}
}
abstract class Animals{
public abstract void cry();
}
Test类2
package InnerClass;
public class Test2 {
public static void main(String[] args) {
Swimming s1 = new Swimming() {
@Override
public void swim() {
System.out.println("swimming fast");
}
};
s1.swim();
go(s1);
}
public static void go(Swimming s){
System.out.println("start");
s.swim();
}
}
interface Swimming{
void swim();
}