Java Encapsulation Constructor Method -
hi working on java code student health. trying is
a) make constructor method initializes first 2 data fields (name , date-of-birth). also, increment patient counter data field.
b) secondly make constructor method initializes data fields. also, increment patient counter data field.
if recall correctly in order make constructor method initializes first 2 variables (in case name , dob) goes this.
public emr (string name, long dob){ however when put in emr class main method comes errors saying "constructor emr class cannot applied given types"
in main method have
package studenthealthservices; public class studenthealthservices { public static void main(string[] args) { emr p1 = new emr(); p1.setname("colin"); emr p2 = new emr(); p2.setname("anquan"); emr p3 = new emr(); p3.setname("buster"); emr p4 = new emr(); p4.setname("hunter"); emr p5 = new emr(); p5.setname("nori"); } } this emr class code
package studenthealthservices; public class emr { private string name; private long dob; private string rfv; private double bodyt; private double hr; private string diag; private string pmeds; public void setname(string name) { this.name = name; } public long getdob() { return dob; } public void setdob(long dob) { this.dob = dob; } public string getrfv() { return rfv; } public void setrfv(string rfv) { this.rfv = rfv; } public double getbodyt() { return bodyt; } public void setbodyt(double bodyt) { this.bodyt = bodyt; } public double gethr() { return hr; } public void sethr(double hr) { this.hr = hr; } public string getdiag() { return diag; } public void setdiag(string diag) { this.diag = diag; } public string getpmeds() { return pmeds; } public void setpmeds(string pmeds) { this.pmeds = pmeds; } }
if not write constructor, public constructor no arguments created default.
this default constructor constructor using in main when write new emr().
however, when write own constructor, default constructor not created, main no longer compile. if want main continue compile after have written new constructor, have write second constructor no arguments.
Comments
Post a Comment