Skip to content

Instantly share code, notes, and snippets.

@MykolaBova
Created October 1, 2016 14:30
Show Gist options
  • Save MykolaBova/3da6a6d313b4d8d3b60cb2a07d5868fa to your computer and use it in GitHub Desktop.
Save MykolaBova/3da6a6d313b4d8d3b60cb2a07d5868fa to your computer and use it in GitHub Desktop.
class HideInstanceVariable {
public static void main(String[] args) {
Car car = new SportCar();
System.out.println(car.getSpeedMax());
}
}
class Car {
private int speedMax = 150;
public int getSpeedMax() {
return speedMax;
}
}
class SportCar extends Car {
private int speedMax = 300;
@Override
public int getSpeedMax() {
return speedMax;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment