Java constructor does not look the way it should -
i referencing y. daniel liang's book "introduction java programming, comprehensive version, ninth edition" when ask question. every time see object created using constructor, goes :
car engine = new car().
but in daniel liang's book, found following code (only first 9 lines written here):
public class simplegeometricobject { private string color = "white"; private boolean filled; private java.util.date datecreated; /** construct default geometric object */ public simplegeometricobject() { datecreated = new java.util.date(); }
what don't understand how come object "datecreated" not created in normal way, ie.:
simplegeometricobject datecreated = new simplegeometrciobject();
i'm confused.
actually datecreated object class date in package java.util , inside object defining simplegeometricobject
in other words java guys wrote this:
package java.util; public class date{ //with own attributes public date(){ ... //and own constructor } ...//and it's own methods }
and provided developpers can use in our own class/objects , way if import package import java.util.date;
in beginning of file need construct date follows : date objectdate = new date();
Comments
Post a Comment