你看一下老毕的视频教程,里面有讲的
- public class Demo17 {
- public static void main(String[] args) {
- Person1 p1=new Person1("A",30);
- Person1 p2=new Person1("B",30);
- System.out.println(p1.compare(p2));
- }
- }
- class Person1{
- String name;
- int age;
- Person1(String name){
- this.name=name;
- }
- Person1(String name,int age){
- this(name);
- this.age=age;
- }
- public boolean compare(Person1 p){
- return this.age==p.age;
- }
- }
复制代码 |