Advertisement
KechevD

Lesson 22 Constructors

Mar 30th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1.  
  2. public class Car {
  3.  
  4. int modelYear;
  5. String modelName;
  6. double price;
  7. String type;
  8.  
  9. public Car() {
  10. this(1969);
  11. }
  12.  
  13. public Car(int modelYear) {
  14. this(modelYear, "Mustang");
  15. }
  16.  
  17. public Car(int modelYear, String modelName) {
  18. this(modelYear, modelName, 120000);
  19. }
  20.  
  21. public Car(int modelYear, String modelName, double price) {
  22. this(modelYear, modelName, 120000, "Ford");
  23. }
  24.  
  25. public Car(int modelYear, String modelName, double price, String type) {
  26. this.modelYear = modelYear;
  27. this.modelName = modelName;
  28. this.price = price;
  29. this.type = type;
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement