I have a class called father that has List vehicles as its variable;
import java.util.List;
public class Father {
String name;
String weight;
String age;
String height;
String country;
List<Vehicle> vehicles;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getHeight() {
return height;
}
public void setHeight(String height) {
this.height = height;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public List<Vehicle> getVehicles() {
return vehicles;
}
public void setVehicles(List<Vehicle> vehicles) {
this.vehicles = vehicles;
}
}
I also have another class called Vehicle
public class Vehicle {
String brand;
String type;
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
I want to get Father's vehicle brand inside a main class.How do I do that? For example i want to print father's vehicle brand,add new vehicle brand and print the last vehicle brand that father has.
This is what I have tried inside a main class
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<Vehicle> vehicleList = new ArrayList<>();
Vehicle vehicle = new Vehicle();
vehicle.setBrand("Toyota");
vehicleList.add(vehicle);
Father father = new Father();
father.setVehicles(vehicleList);
System.out.println(father.getVehicles());
}
}
The result that i get is [Vehicle@15db9742]