zoukankan      html  css  js  c++  java
  • 代理Delegation

    package com.ctl.test;
    
    class Person {
    	private int id;
    	private String name;
    
    	public int getId() {
    		return id;
    	}
    
    	public void setId(int id) {
    		this.id = id;
    	}
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public Person(int id, String name) {
    		super();
    		this.id = id;
    		this.name = name;
    	}
    
    	public Person() {
    		super();
    	}
    
    	public void say(String name) {
    		System.out.println("my name is" + name);
    	}
    
    	public void run() {
    		System.out.println("-----run start-----");
    		for (int i = 0; i < 5; i++) {
    			try {
    				Thread.sleep(200);
    				System.out.println("i=" + i);
    			} catch (InterruptedException e) {
    				e.printStackTrace();
    			}
    		}
    		System.out.println("-----run start-----");
    	}
    
    	public void study() {
    		System.out.println("study");
    	}
    
    	public void work() {
    		System.out.println("work");
    	}
    }
    
    class PersonDelegation {
    	private String name;
    
    	public PersonDelegation(String name) {
    		super();
    		this.name = name;
    	}
    
    	public Person getPerson() {
    		return person;
    	}
    
    	public void setPerson(Person person) {
    		this.person = person;
    	}
    
    	private Person person = new Person(1, name);
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public void work() {
    		person.work();
    	}
    	
    	public void run(){
    		person.run();
    	}
    }
    
    public class PersonDelegationTest {
    	public static void main(String[] args) {
    		PersonDelegation per = new PersonDelegation("lin");
    		per.work();
    		per.run();
    	}
    }
    

  • 相关阅读:
    VS快捷键
    eclipse快捷键(shift+ctrl+l能出来所有的快捷键)
    永远不要觉得自己代码有多6
    winform中使用webBrowser时如何与JS交互
    HTML CSS
    HTTP 协议 session cookie
    [Python3]Python官方文档-Python Manuals
    [python3]PyCharm编辑器
    Loadrunner上传文件与下载文件脚本
    Spotlight安装
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/6791642.html
Copyright © 2011-2022 走看看