zoukankan      html  css  js  c++  java
  • 使用匿名内部类调用start方法

    package chapter03;
    //类实现接口
    public class WD implements Runnable{
    //重写接口的方法

    @Override
    public void run() {
    for(int i=0; i<500; i++) {
    System.out.println("我是豌豆,发炮弹:" + i);
    }

    }

    }

    -------------------

    package chapter03;

    public class Zombies implements Runnable {

    @Override
    public void run() {
    for(int i=0; i<500; i++) {
    System.out.println("我是僵尸,往前走" + i);
    }

    }

    }

    ----------------------------------

    package chapter03;
    /**
    * 使用线程模拟简单植物大战僵尸
    *
    */
    public class TestPlantsVSZombies {

    public static void main(String[] args) {
    // 匿名内部类创建对象和调用方法
    new Thread(new WD()).start();

    new Thread(new Zombies()).start();
    /*
    * // 创建豌豆对象 WD wd = new WD(); // 创建僵尸对象 Zombies zombies = new
    * Zombies();
    *
    * // 线程一执行豌豆的攻击操作 Thread t1 = new Thread(wd);
    *
    * // 线程二执行僵尸的前进操作 Thread t2 = new Thread(zombies);
    *
    * t1.start(); t2.start();
    */

    }

    }

  • 相关阅读:
    POI中文API文档
    接口
    JDK中的URLConnection参数详解
    RPC远程过程调用概念及实现
    tkinter 打包成exe可执行文件
    PHP 的命令行模式
    php CLI SAPI 内置Web Server
    ppython的移位操作
    HAProxy基础
    HAProxy用法详解
  • 原文地址:https://www.cnblogs.com/Koma-vv/p/9616289.html
Copyright © 2011-2022 走看看