package com.mianshi.test;
/**
* 类名称:AnonymousInnerClassTest
* 描述: 匿名内部类测试
* 创建人:王秋林
* 创建时间:2017-2-12
*/
public class AnonymousInnerClassTest {
public static void main(String args[]){
AnonymousInnerClassTest test = new AnonymousInnerClassTest();
test.show();
}
//在这个方法中构造了一个匿名内部类
private void show(){
Out anonyInter = new Out(){//获取匿名内部类实例
void show(){//重写父类的方法
System.out.println("this is Anonymous InnerClass showing.");
}
};
anonyInter.show();//调用其方法
}
}
//这是一个已经存在的类,匿名内部类通过重写其方法,将会获得另外的实现
class Out{
void show(){
System.out.println("this is Out showing.");
}
}
abstract class Person {
public abstract void eat();
}
public class Demo {
public static void main(String[] args) {
Person p = new Person() {
public void eat() {
System.out.println("eat something");
}
};
p.eat();
}
}
interface Person {
public void eat();
}
public class Demo {
public static void main(String[] args) {
Person p = new Person() {
public void eat() {
System.out.println("eat something");
}
};
p.eat();
}
}
public class Demo {
public static void main(String[] args) {
Thread t = new Thread() {
public void run() {
for (int i = 1; i <= 5; i++) {
System.out.print(i + " ");
}
}
};
t.start();
}
}
public class Demo {
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
for (int i = 1; i <= 5; i++) {
System.out.print(i + " ");
}
}
};
Thread t = new Thread(r);
t.start();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有