Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Human{
- String imie;
- String nazwisko;
- int wiek;
- public Human(String nazwisko, String imie, int wiek){
- this.nazwisko=nazwisko;
- this.imie=imie;
- this.wiek=wiek;
- }
- public int hashCode(){
- return wiek;
- }
- public boolean equals(Object obj){
- Human otherHuman= (Human) obj;
- return nazwisko.equals(otherHuman.nazwisko);
- }
- public static void main(){
- Human human1 = new Human("Jan", "Kowalski", 85);
- Human human2 = new Human("Jan", "Lis", 20);
- Human human3 = new Human("Marek", "Kowalski", 20);
- System.out.println(human1 + " == " + human2 + " " + human1.equals(human2));
- System.out.println(human2 + " == " + human3 + " " + human2.equals(human3));
- System.out.println(human1 + " == " + human3 + " " + human1.equals(human3));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement