Solved

Need help on Clonning objects in Java

Posted on 2016-08-01
4
46 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 88
Weekend adv creator 3 38
eclipse console opening separately 2 19
Glassfish admin console not working 1 12
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

770 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