Guest User

Untitled

a guest
Jul 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.34 KB | None | 0 0
  1. class Car {
  2.  
  3.   private String color;
  4.  
  5.   Car(String newColor) {
  6.     color = newColor;
  7.   }
  8.  
  9.   void showColor() {
  10.     System.out.println(this.color);
  11.   }
  12. }
  13.  
  14. Car car1 = new Car("red");
  15. Car car2 = new Car("blue");
  16.  
  17. car1.showColor(); // this -> car1 -> this.color == car1.color
  18. car2.showColor(); // this -> car2 -> this.color == car2.color
Add Comment
Please, Sign In to add comment