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); |
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 Hash2 { | |
public static void main(String[] args) { | |
Car car1 = new Car(12345, 14); | |
Car car2 = new Car(12345, 14); | |
Car car3 = new Car(789, 23); | |
System.out.println(car1.hashCode()); | |
System.out.println(car2.hashCode()); | |
System.out.println(car3.hashCode()); |
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 Hash2 { | |
public static void main(String[] args) { | |
Car car1 = new Car(12345); | |
Car car2 = new Car(12345); | |
Car car3 = new Car(789); | |
System.out.println(car1.hashCode()); | |
System.out.println(car2.hashCode()); | |
System.out.println(car3.hashCode()); |
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 Hash { | |
public static void main(String[] args) { | |
Car car1 = new Car(12345); | |
Car car2 = new Car(12345); | |
Car car3 = new Car(789); | |
System.out.println(car1.hashCode()); | |
System.out.println(car2.hashCode()); | |
System.out.println(car3.hashCode()); |
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 Equals2 { | |
public static void main(String[] args) { | |
Car car1 = new Car(12345); | |
Car car2 = new Car(12345); | |
Car car3 = car1; | |
System.out.println(car1.equals(car2)); | |
System.out.println(car1.equals(car3)); | |
} |
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 Equals { | |
public static void main(String[] args) { | |
Car car1 = new Car(12345); | |
Car car2 = new Car(12345); | |
Car car3 = car1; | |
System.out.println(car1.equals(car2)); | |
System.out.println(car1.equals(car3)); | |
} | |
} |
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 ToString2 { | |
public static void main(String[] args) { | |
Car car = new SportCar(); | |
System.out.println(car); | |
} | |
} | |
class Car { | |
protected int speedMax = 100; |
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 ToString { | |
public static void main(String[] args) { | |
Car car = new SportCar(); | |
System.out.println(car); | |
} | |
} | |
class Car { | |
protected int speedMax = 100; |
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 HideInstanceVariable { | |
public static void main(String[] args) { | |
Car car = new SportCar(); | |
System.out.println(car.getSpeedMax()); | |
} | |
} | |
class Car { | |
protected int speedMax = 100; |
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 Overriding { | |
public static void main(String[] args) { | |
Car car = new SportCar(); | |
System.out.println(car.getSpeedMax()); | |
} | |
} | |
class Car { | |
protected int speedMax = 150; |