class Protected {
Car myCar1 = new Car(12,125);
// int i = myCar1.speedMax;
}
}
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
return "My name is car." + "speedMax = " + speedMax + "id = " + id;
}
public Car getNewCar() {
return new Car();
}
protected void move() {
System.
out.
println("Car move."); }
@Override
return super.clone();
}
}
class Truck extends Car {
@Override
protected void move() {
System.
out.
println("Truck move."); }
}
class SportCar extends Car {
protected int speedMax = 300;
public SportCar(long id, int speedMax) {
super(id, speedMax);
}
public SportCar() {
}
public int getSpeedMax() {
return speedMax;
}
@Override
return super.toString() + "Sport car.";
}
public void testSuper() {
System.
out.
println(super.
speedMax); System.
out.
println(this.
speedMax); }
@Override
public SportCar getNewCar() {
return new SportCar();
}
@Override
public void move() {
System.
out.
println("Sport car move."); }
}
Y2xhc3MgUHJvdGVjdGVkIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBDbG9uZU5vdFN1cHBvcnRlZEV4Y2VwdGlvbiB7CgogICAgICAgIENhciBteUNhcjEgPSBuZXcgQ2FyKDEyLDEyNSk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKG15Q2FyMSk7CgogICAgICAgIC8vIGludCBpID0gbXlDYXIxLnNwZWVkTWF4OwogICAgfQp9CgpjbGFzcyBDYXIgaW1wbGVtZW50cyBDbG9uZWFibGV7CiAgICBwcm90ZWN0ZWQgaW50IHNwZWVkTWF4ID0gMTAwOwogICAgcHJpdmF0ZSBsb25nIGlkOwoKCiAgICBwdWJsaWMgQ2FyKGxvbmcgaWQsIGludCBzcGVlZE1heCkgewogICAgICAgIHRoaXMuaWQgPSBpZDsKICAgICAgICB0aGlzLnNwZWVkTWF4ID0gc3BlZWRNYXg7CiAgICB9CgogICAgcHVibGljIENhcigpIHsKCiAgICB9CgogICAgQE92ZXJyaWRlCiAgICBwdWJsaWMgaW50IGhhc2hDb2RlKCkgewogICAgICAgIGludCByZXN1bHQgPSAoaW50KSAoaWQgXiAoaWQgPj4+IDMyKSk7CiAgICAgICAgcmVzdWx0ID0gMzEgKiByZXN1bHQgKyBzcGVlZE1heDsKICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgfQoKICAgIEBPdmVycmlkZQogICAgcHVibGljIGJvb2xlYW4gZXF1YWxzKE9iamVjdCBvKSAgewogICAgICAgIGlmKHRoaXMgPT0gbykgcmV0dXJuIHRydWU7CiAgICAgICAgaWYobyA9PSBudWxsIHx8IGdldENsYXNzKCkgIT0gby5nZXRDbGFzcygpKSByZXR1cm4gZmFsc2U7CiAgICAgICAgQ2FyIGNhciA9IChDYXIpIG87CiAgICAgICAgaWYoaWQgIT0gY2FyLmlkKSByZXR1cm4gZmFsc2U7CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBwdWJsaWMgaW50IGdldFNwZWVkTWF4KCkgewogICAgICAgIHJldHVybiBzcGVlZE1heDsKICAgIH0KCiAgICBAT3ZlcnJpZGUKICAgIHB1YmxpYyBTdHJpbmcgdG9TdHJpbmcoKSB7CiAgICAgICAgcmV0dXJuICJNeSBuYW1lIGlzIGNhci4iICsgInNwZWVkTWF4ID0gIiArIHNwZWVkTWF4ICsgImlkID0gIiArIGlkOwogICAgfQoKICAgIHB1YmxpYyBDYXIgZ2V0TmV3Q2FyKCkgewogICAgICAgIHJldHVybiBuZXcgQ2FyKCk7CiAgICB9CgogICAgcHJvdGVjdGVkIHZvaWQgbW92ZSgpIHsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkNhciBtb3ZlLiIpOwogICAgfQoKICAgIEBPdmVycmlkZQogICAgcHVibGljIE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