Link to home
Start Free TrialLog in
Avatar of Swaminathan K
Swaminathan KFlag for India

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
Avatar of CPColin
CPColin
Flag of United States of America image

I don't get the error you're getting. Is that the exact code you're running?

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.
Avatar of Swaminathan K

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
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
can you also share the test class - EmployeeTest.java?