Biblioteca Java - Blame information for rev 36
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
36 | mihai | 1 | |
2 | public class Person { | ||
3 | |||
4 | private long cnp; | ||
5 | private String name; | ||
6 | |||
7 | Person(String name, long cnp){ | ||
8 | this.name = name; | ||
9 | this.cnp = cnp; | ||
10 | } | ||
11 | |||
12 | @Override | ||
13 | public boolean equals(Object obj) { | ||
14 | if(obj instanceof Person){ | ||
15 | Person p = (Person)obj; | ||
16 | return cnp == p.cnp; | ||
17 | } | ||
18 | return false; | ||
19 | } | ||
20 | |||
21 | public static void main(String[] args) { | ||
22 | Person p1 = new Person("Alin",12345); | ||
23 | Person p2 = new Person("Dan",12345); | ||
24 | if(p1.equals(p2)) | ||
25 | System.out.println(p1+" and "+p2+ " are equals"); | ||
26 | else | ||
27 | System.out.println(p1+" and "+p2+ " are NOT equals"); | ||
28 | |||
29 | if(p1==p2) //GRESIT ! | ||
30 | System.out.println(p1+" and "+p2+ " are equals"); | ||
31 | else | ||
32 | System.out.println(p1+" and "+p2+ " are NOT equals"); | ||
33 | |||
34 | //Comparare stringuri | ||
35 | if(p1.name.equals(p2.name)) | ||
36 | System.out.println(p1+" and "+p2+" have the same names"); | ||
37 | else | ||
38 | System.out.println(p1+" and "+p2+" have different names"); | ||
39 | } | ||
40 | } | ||
41 |