11.06第十次作业

package cn.wzx.www;

public class Hellow {
    public static void main(String[] args) 
    {
    new Hellow().fun();
    }

    public void fun()
    {
    System.out.println("Hello World!");
    }
}

package cn.wzx.www;
public class Person {
    private String name;
    private int age;
    public Person(String name, int age) {
        this.name=name;
        this.age=age;
    }
    public boolean compare (Person per){
        if(this.name.equals(per.name)&&this.age==per.age){
            return true;
        }
        else
        {
            return false;
        }
    }
        public String getName(){
            return this.name;
        }
        public int getAge(){
            return this.age;
        }

    public static  void main(String[] args) {
        // TODO 自动生成的方法存根
        Person per1=new Person("张三",30);
        Person per2=new Person("张三",30);
        if(per1.compare(per2)){
            System.out.println("是同一个人!");
        }

    }

}

 

package cn.wzx.www;
public class Person1 {
    private String name;
    private int age;
    public Person1(String name, int age) {
        this.name=name;
        this.age=age;
    }
    /*public boolean compare (Person1 per){
        if(this==per){
            return true;
            }
        if(this.name.equals(per.name)&&this.age==per.age){
            return true;
        }
        else
        {
            return false;
        }
    }*/
    public  boolean compare (Person1 per){
        if(this==per){
            System.out.println("dui");
            }
        if(this.name.equals(per.name)&&this.age==per.age){
            
            System.out.println("是同一个人!");
        }
        else
        {
            
            System.out.println("不是同一个人!");
        }
        return false;
    }
        public String getName(){
            return this.name;
        }
        public int getAge(){
            return this.age;
        }

    public static  void main(String[] args) {
        // TODO 自动生成的方法存根
        Person1 per1=new Person1("张三",30);
        Person1 per2=new Person1("李四",30);
        /*if(per1.compare(per2)){
            System.out.println("是同一个人!");
        }*/
        per1.compare(per2);
        System.out.println(per1.getAge());
        System.out.println(per2.getName());

    }

}

 

package cn.wzx.www;

public class Person2 {
    private String name;
    private int age;
    public Person2(String name,int age){
        this.name=name;
        this.age=age;
    }
    public void fun(Person2 temp){
        temp.name="李四";
        temp.age=33;
    }
    public String getName(){
        return this.name;
    }
    public int getAge(){
        return this.age;
    }

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Person2 per=new Person2("张三",30);
        per.fun(per);
        System.out.println(per.getName()+"-->"+per.getAge());

    }

}

 

package cn.wzx.www;

public class Person3 {
    private String name;
    private int age;
    public Person3(String name,int age){
        this.name=name;
        this.age=age;
    }
    
    public String getName(){
        return this.name;
    }
    public int getAge(){
        return this.age;
    }

    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Person3 per1=new Person3("张三",30);
        Person3 per2=new Person3("张三",30);
        if(per1.getName().equals(per2.getName())&&per1.getAge()==per2.getAge()){
            System.out.println("是同一个人!");
        }

    }

}

posted on 2017-11-13 13:56  老张的小迷妹儿  阅读(124)  评论(0编辑  收藏  举报

导航