Journey to Java: Episode 7 “OOP Continued and the Constructor”

(BaseballTeam orioles = new BaseballTeam(); 
public class BaseballTeam {   public BaseballTeam() {
System.out.println("we are in the constructor")
}
}
public class BaseballTeam {   public BaseballTeam(String city, String name, 
String colorOne,String colorTwo) {
this.city = city;
this.name = name;
this.colorOne = colorOne;
this.colorTwo = colorTwo;
}}
//inside main
BaseballTeam orioles = new BaseballTeam("Baltimore", "Orioles", "Orange", "Black")
public class BaseballTeam {   public BaseballTeam() {
this("No city", "no mascot", "no color", "no color");
}}
//best practice
public class BaseballTeam {
public BaseballTeam(String city, String name,
String colorOne,String colorTwo) {
this.city = city;
this.name = name;
this.colorOne = colorOne;
this.colorTwo = colorTwo;
}}//works too but may cause issuespublic class BaseballTeam {public BaseballTeam(String city, String name,
String colorOne,String colorTwo) {
this.setCity(city);
this.setName(name);
this.setColorOne(colorOne);
this.setColorTwo(colorTwo);
}}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store