Created
October 1, 2016 16:20
-
-
Save MykolaBova/2edf6ad6c8f189b71a4f67f435ad63c9 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 Super2 { | |
public static void main(String[] args) { | |
SportCar car3 = new SportCar(789, 23); | |
car3.testSuper(); | |
} | |
} | |
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."; | |
} | |
public void testSuper() { | |
System.out.println(super.speedMax); | |
System.out.println(this.speedMax); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment