I have started to learn OOP and I understand the concept of a class, I understand that by using constructors we can shield our class from the rest of the program but I would like to know more about the relationship between the class and its constructor.
When I set up a constructor, it is initializing my instance variables but is it duplicating my class and then I am dealing with just the constructor or is it being used as an intermediary between my class and the rest of my program i.e does it pass information into the class?
Here is an example of a program I made last week.
class Pets
{
private String breed ;
private String coat ;
private String temperment ;
//constructors with 3 parameters and 3 instance variables.
public Pets ( String aBreed, String aCoat, String aTemperment )
{
breed = aBreed ;
coat = aCoat ;
temperment = aTemperment ;
}
//Setters
public void setBreed ( String aBreed ) { breed = aBreed ; }
public void setCoat ( String aCoat ) { coat = aCoat ; }
public void setTemperment ( String aTemperment ) { temperment = aTemperment ; }
//Getters
public String getBreed() { return breed ; }
public String getCoat() { return coat ; }
public String getTemperment() { return temperment ; }
//petDisplay - A method to print information about pets.
public void petDisplay()
{
System.out.println ( "This pet is a " + breed + ", it has a " + coat + " coat and is " + temperment + "." ) ;
}