Swaminathan K
asked on
Need help on Clonning objects in Java
Hi Team,
Below is the code which I have wriiten to check the number of instances created for an Class called as Employee.
Somehow the code does not gives the expected output. Iam used a method called as checkinstances to check the number of instances created for the Employee class .
If it is equal to 3 , I throwing an exception. Also Iam checking the number of intances created using the overridden method called CheckInstances in both Clone and in constructor.
Any help in is really appreciated.
Employee.java
Below is the code which I have wriiten to check the number of instances created for an Class called as Employee.
Somehow the code does not gives the expected output. Iam used a method called as checkinstances to check the number of instances created for the Employee class .
If it is equal to 3 , I throwing an exception. Also Iam checking the number of intances created using the overridden method called CheckInstances in both Clone and in constructor.
Any help in is really appreciated.
Employee.java
ASKER
Yes , My question is , is i the right way to create an count of objects for an Class using constructors and clone method .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
can you also share the test class - EmployeeTest.java?
Try adding some debug logging in every place where you're incrementing your counter. Have it log something like "In Employee()" or "In clone()" and see how many times each operation is happening.