Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need help on Clonning objects in Java

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

Expert Comment

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
factorial example 4 48
use lov values 2 63
CSV file parsing thru Java 13 34
learn programming 8 42
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

828 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