Skip to content

Commit

Permalink
Pass Object and Overloaded Constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
KatsuMouley committed May 10, 2024
1 parent 3eb59b5 commit 39add6c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Objects/Car.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package Objects;

public class Car extends Vehicle {


public String name;
public String make = "Chevrolet";
public String model = "Corvette";
public int year = 2020;
public String color = "blue";
public double price = 50000.00;

public Car(){}
public Car(String name){
this.name = name;
}

public void drive() {
System.out.println("You drive the car");
Expand Down
9 changes: 9 additions & 0 deletions src/Objects/Garage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package Objects;
public class Garage {

public Garage(){}

public void Park(Car car/*Since car is inside the same package of Garage, which is Objects, we can use it inside this object without the need to import the package*/){
System.out.println("The "+ car.name +" is parked in the Garage");
}
}
5 changes: 5 additions & 0 deletions src/files/OverloadedCons.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ public static void run() {
Bake pizzariaBakingType3 = new Bake("massa", "molho");
Bake pizzariaBakingType4 = new Bake("massa", "molho", "queijo");
Bake pizzariaBakingType5 = new Bake("massa", "molho", "queijo", "recheio");
System.out.println(pizzariaBakingType1.bread+'\n');
System.out.println(pizzariaBakingType2.bread+'\n');
System.out.println(pizzariaBakingType3.sauce+'\n');
System.out.println(pizzariaBakingType4.cheese+'\n');
System.out.println(pizzariaBakingType5.toping+'\n');
}
}
8 changes: 8 additions & 0 deletions src/files/PassObject.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package files;
import Objects.Car;
import Objects.Garage;
public class PassObject {
public static void main(String[] args) {
run();
}
//How to pass objects as arguments?
public static void run() {
Garage garage = new Garage();
Car car1 = new Car("BMW");
Car car2 = new Car("Tesla");
garage.Park(car1);
garage.Park(car2);
}
}

0 comments on commit 39add6c

Please sign in to comment.