oop - Different objects with the same data java -
oop - Different objects with the same data java -
i have created class creates instance of object
public class employeeprofile { /////////instance variables///////// private static string fname; private static string lname; private static string email; private static string phone; ////////constructors//////////// public employeeprofile() { } public employeeprofile(string firstname, string lastname, string emailadd, string pnumber) { fname = firstname; lname = lastname; email = emailadd; phone = pnumber; } }
when phone call empty constructor , populate myself methods i've created fine. when phone call new object new name using sec constructor , parameters, overwrite info first object!!
employeeprofile prof1 = new employeeprofile(); prof1.firstname("john"); prof1.lastname("doe"); prof1.email("johndoe@yahoo.com"); prof1.phone("555-555-5555"); employeeprofile prof2 = new employeeprofile("jane", "doe", "janedoe@yahoo.com", "555-123-4567"); system.out.println(prof1.getprofile()); system.out.println(prof2.getprofile());
when run prof1 , prof2 both homecoming info prof2. doing wrong here?
/////////instance variables///////// private static string fname; private static string lname; private static string email; private static string phone;
the comment , code inconsistent. static
signifies class variables, not instance. therefore, they're shared between class instances.
java oop object
Comments
Post a Comment