Created
October 1, 2016 16:09
-
-
Save MykolaBova/22335dacb81f954a68dc6e23e070470e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Super { | |
public static void main(String[] args) { | |
Car car1 = new Car(12345, 14); | |
Car car2 = new Car(12345, 14); | |
Car car3 = new SportCar(789, 23); | |
System.out.println(car1); | |
System.out.println(car2); | |
System.out.println(car3); | |
} | |
} | |
class Car { | |
protected int speedMax = 100; | |
private long id; | |
public Car(long id, int speedMax) { | |
this.id = id; | |
this.speedMax = speedMax; | |
} | |
public Car() { | |
} | |
@Override | |
public int hashCode() { | |
int result = (int) (id ^ (id >>> 32)); | |
result = 31 * result + speedMax; | |
return result; | |
} | |
@Override | |
public boolean equals(Object o) { | |
if(this == o) return true; | |
if(o == null || getClass() != o.getClass()) return false; | |
Car car = (Car) o; | |
if(id != car.id) return false; | |
return true; | |
} | |
public int getSpeedMax() { | |
return speedMax; | |
} | |
@Override | |
public String toString() { | |
return "My name is car."; | |
} | |
} | |
class SportCar extends Car { | |
protected int speedMax = 300; | |
public SportCar(long id, int speedMax) { | |
super(id, speedMax); | |
} | |
public int getSpeedMax() { | |
return speedMax; | |
} | |
@Override | |
public String toString() { | |
return super.toString() + "Sport car."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment