I'm trying to figure out how to create a class through a constructor's parameters here is my code:
public class Article { private String title; private String body; private ArrayList <Author> authors = new ArrayList<Author>(); // this isn't how I'm supposed to create the object private GregorianCalendar pubDate = new GregorianCalendar(); // this isn't how I'm supposed to create the object private boolean published; private SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd 'at' hh:mm:ss"); public Article(String title) { this.title = title; } public Article(String title, String body, ArrayList<Author> author, GregorianCalendar pubDate, boolean published) { this.title = title; this.body = body; this.authors = author; //somehow I'm supposed to pass the author class to this and create an arraylist this.pubDate = pubDate; // this.pubDate.set(year, month - 1, dayOfMonth, hour, minute); this.published = published; }
My teacher says I shouldn't instantiate in the private fields (*or this is what I think he meant). If I create a object inside the constructor, where will the field be stored? wouldn't the object disappear? Do I have to create the object in the private fields area first?