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);
}}

--

--

--

Student at The Flatiron School in Washington DC

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Branching Models in a nutshell

Keras with GPU on Amazon EC2 – a step-by-step instruction

Filling the Gaps: Assorted Dev Readings

Introduction to Single Linked Lists using C

Governance Period 2 Payouts

ActiveRecord Callbacks

How to Sort Out Tech Debt and Speed-up Development

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
Adam Adolfo

Adam Adolfo

Student at The Flatiron School in Washington DC

More from Medium

Linux Commands

Travel Trends

New Features in Pointly

New features in Pointly

CS371p Spring 2022: Christopher Carrasco — Week 9