Solved

Need help on Clonning objects in Java

Posted on 2016-08-01
4
44 Views
Last Modified: 2016-08-06
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
0
Comment
Question by:sam_2012
4 Comments
 
LVL 14

Expert Comment

by:CPColin
ID: 41737814
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.
0
 

Author Comment

by:sam_2012
ID: 41738155
Yes , My question is , is i the right way to create an count of objects for an Class  using constructors and clone method .
0
 
LVL 16

Accepted Solution

by:
krakatoa earned 500 total points
ID: 41738227
Your code would count the instances correctly as far as I can see. You increment the count twice, and two objects are created, which seems ok.
1
 
LVL 15

Expert Comment

by:gurpsbassi
ID: 41738956
can you also share the test class - EmployeeTest.java?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is the latest versions eclipse neon 2 139
printing a file in reverse order is easy in recursion rather than in iteration 3 48
eclipse shortcuts 9 45
MySQL  on Tomcat 8 23
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now