{"id":221,"date":"2012-11-11T19:22:23","date_gmt":"2012-11-11T19:22:23","guid":{"rendered":"http:\/\/ilias-laptop\/examples\/core-java\/class\/copy-constructor-example\/"},"modified":"2013-07-22T01:09:26","modified_gmt":"2013-07-21T22:09:26","slug":"copy-constructor-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/","title":{"rendered":"Copy Constructor example"},"content":{"rendered":"<p>This is an example of how to create a copy constructor in a class.\u00a0We have set the example, in order to demonstrate the copy constructor and its use between classes and their subclasses following the steps below:<\/p>\n<ul>\n<li>We have created <code>FruitQualities<\/code> class, <code>Seed<\/code> class and <code>Fruit<\/code> class, that all have copy constructor.\u00a0<\/li>\n<li>We have also created <code>Tomato<\/code> class, that extends <code>Fruit<\/code>, <code>ZebraQualities<\/code> class that extends <code>FruitQualities<\/code>, and <code>GreenZebra<\/code> class that extends <code>Tomato<\/code>. All subclasses call their super classes&#8217; copy constructors in their copy constructors.<\/li>\n<li>We create a new instance of <code>Tomato<\/code>, that is tomato.<\/li>\n<li>We call <code>ripenFunc(Tomato t)<\/code>, using the tomato, where we use its copy constructor to create another new instance. We get the name of the class of the object created, using <code>getClass()<\/code> and <code>getName()<\/code> API methods of <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/lang\/Class.html\" target=\"_blank\">Class<\/a>. The object created belongs to <code>Tomato<\/code> class.<\/li>\n<li>We call <code>sliceFunc(Fruit f)<\/code>, using the tomato. This method creates a new <code>Fruit<\/code> instance, using the copy constructor. The object created belongs to <code>Fruit<\/code> class.<\/li>\n<li>We call <code>ripenFunc2(Tomato t)<\/code>, using the tomato, where we get the <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/lang\/reflect\/Constructor.html\" target=\"_blank\">Constructor<\/a> of the object, using its class name, with <code>getClass()<\/code> API method and using its constructor, with <code>getConstructor()<\/code> API method of Class. Then we use the <code>newInstance(Object... initargs)<\/code> API method of Constructor to get a new instance of the object. The object belongs to <code>Tomato<\/code> class. <\/li>\n<li>We call <code>sliceFunc2(Fruit f)<\/code>, using the tomato, that does the same steps as <code>ripenFunc2(Tomato t)<\/code> does, with a <code>Fruit<\/code> f as parameter. The object created belongs to <code>Tomato<\/code> class. <\/li>\n<li>We follow the same steps, creating an instance of <code>GreenZebra<\/code>, that extends the <code>Tomato<\/code> class. The results from the two first methods are,\u00a0first a <code>Tomato<\/code> object, then a <code>Fruit<\/code> object, whereas in the last two methods a <code>GreenZebra<\/code> object is created.<\/li>\n<\/ul>\n<p>Let\u2019s take a look at the code snippet that follows:\u00a0<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\">\r\npackage com.javacodegeeks.snippets.core;\r\n\r\nimport java.lang.reflect.Constructor;\r\nimport java.lang.reflect.InvocationTargetException;\r\n\r\nclass FruitQualities {\r\n\r\n    private int w;\r\n    private int c;\r\n    private int firmval;\r\n    private int ripen;\r\n    private int sml;\r\n\r\n    \/\/ etc.\r\n    public FruitQualities() { \/\/ Default constructor\r\n\r\n  \/\/ Do something meaningful...\r\n    }\r\n\r\n    \/\/ Other constructors:\r\n    \/\/ ...\r\n    \/\/ Copy constructor:\r\n    public FruitQualities(FruitQualities frq) {\r\n\r\n  w = frq.w;\r\n\r\n  c = frq.c;\r\n\r\n  firmval = frq.firmval;\r\n\r\n  ripen = frq.ripen;\r\n\r\n  sml = frq.sml;\r\n\r\n  \/\/ etc.\r\n    }\r\n}\r\n\r\nclass Seed {\r\n    \/\/ Members...\r\n\r\n    public Seed() { \/*\r\n\r\n   * Default constructor\r\n\r\n   *\/\r\n\r\n    }\r\n\r\n    public Seed(Seed s) { \/*\r\n\r\n   * Copy constructor\r\n\r\n   *\/\r\n\r\n    }\r\n}\r\n\r\nclass Fruit {\r\n\r\n    private FruitQualities fq;\r\n    private int seedamnt;\r\n    private Seed[] s;\r\n\r\n    public Fruit(FruitQualities q, int seedCount) {\r\n\r\n  fq = q;\r\n\r\n  seedamnt = seedCount;\r\n\r\n  s = new Seed[seedamnt];\r\n\r\n  for (int i = 0; i &lt; seedamnt; i++) {\r\n\r\n\r\ns[i] = new Seed();\r\n\r\n  }\r\n    }\r\n\r\n    \/\/ Other constructors:\r\n    \/\/ ...\r\n    \/\/ Copy constructor:\r\n    public Fruit(Fruit f) {\r\n\r\n  fq = new FruitQualities(f.fq);\r\n\r\n  seedamnt = f.seedamnt;\r\n\r\n  s = new Seed[seedamnt];\r\n\r\n  \/\/ Call all Seed copy-constructors:\r\n\r\n  for (int i = 0; i &lt; seedamnt; i++) {\r\n\r\n\r\ns[i] = new Seed(f.s[i]);\r\n\r\n  }\r\n\r\n  \/\/ Other copy-construction activities...\r\n    }\r\n\r\n    \/\/ To allow derived constructors (or other\r\n    \/\/ methods) to put in different qualities:\r\n    protected void addQualities(FruitQualities q) {\r\n\r\n  fq = q;\r\n    }\r\n\r\n    protected FruitQualities getQualities() {\r\n\r\n  return fq;\r\n    }\r\n}\r\n\r\nclass Tomato extends Fruit {\r\n\r\n    public Tomato() {\r\n\r\n  super(new FruitQualities(), 100);\r\n    }\r\n\r\n    public Tomato(Tomato t) { \/\/ Copy-constructor\r\n\r\n  super(t); \/\/ Upcast for base copy-constructor\r\n\r\n  \/\/ Other copy-construction activities...\r\n    }\r\n}\r\n\r\nclass ZebraQualities extends FruitQualities {\r\n\r\n    private int stripedness;\r\n\r\n    public ZebraQualities() { \/\/ Default constructor\r\n\r\n  super();\r\n\r\n  \/\/ do something meaningful...\r\n    }\r\n\r\n    public ZebraQualities(ZebraQualities z) {\r\n\r\n  super(z);\r\n\r\n  stripedness = z.stripedness;\r\n    }\r\n}\r\n\r\nclass GreenZebra extends Tomato {\r\n\r\n    public GreenZebra() {\r\n\r\n  addQualities(new ZebraQualities());\r\n    }\r\n\r\n    public GreenZebra(GreenZebra g) {\r\n\r\n  super(g); \/\/ Calls Tomato(Tomato)\r\n\r\n  \/\/ Restore the right qualities:\r\n\r\n  addQualities(new ZebraQualities());\r\n    }\r\n\r\n    public void evaluate() {\r\n\r\n  ZebraQualities zq = (ZebraQualities) getQualities();\r\n\r\n  \/\/ Do something with the qualities\r\n\r\n  \/\/ ...\r\n    }\r\n}\r\n\r\npublic class CopyConstructor {\r\n\r\n    public static void main(String[] args) {\r\n\r\n  Tomato tomato = new Tomato();\r\n\r\n  ripenFunc(tomato); \/\/ OK\r\n\r\n  sliceFunc(tomato); \/\/ OOPS!\r\n\r\n  ripenFunc2(tomato); \/\/ OK\r\n\r\n  sliceFunc2(tomato); \/\/ OK\r\n\r\n  GreenZebra g = new GreenZebra();\r\n\r\n  ripenFunc(g); \/\/ OOPS!\r\n\r\n  sliceFunc(g); \/\/ OOPS!\r\n\r\n  ripenFunc2(g); \/\/ OK\r\n\r\n  sliceFunc2(g); \/\/ OK\r\n\r\n  g.evaluate();\r\n\r\n    }\r\n\r\n    public static void ripenFunc(Tomato t) {\r\n\r\n  \/\/ Use the \"copy constructor\":\r\n\r\n  t = new Tomato(t);\r\n\r\n  System.out.println(\"In ripen, t is a \" + t.getClass().getName());\r\n    }\r\n\r\n    public static void sliceFunc(Fruit f) {\r\n\r\n  f = new Fruit(f); \/\/ Hmmm... will this work?\r\n\r\n  System.out.println(\"In slice, f is a \" + f.getClass().getName());\r\n    }\r\n\r\n    public static void ripenFunc2(Tomato t) {\r\n\r\n  try {\r\n\r\n\r\nClass c = t.getClass();\r\n\r\n\r\n\/\/ Use the \"copy constructor\":\r\n\r\n\r\nConstructor ct = c.getConstructor(new Class[]{c});\r\n\r\n\r\nObject obj = ct.newInstance(new Object[]{t});\r\n\r\n\r\nSystem.out.println(\"In ripen2, t is a \" + obj.getClass().getName());\r\n\r\n  } catch (Exception e) {\r\n\r\n\r\nSystem.out.println(e);\r\n\r\n  }\r\n    }\r\n\r\n    public static void sliceFunc2(Fruit f) {\r\n\r\n  try {\r\n\r\n\r\nClass c = f.getClass();\r\n\r\n\r\nConstructor ct = c.getConstructor(new Class[]{c});\r\n\r\n\r\nObject obj = ct.newInstance(new Object[]{f});\r\n\r\n\r\nSystem.out.println(\"In slice2, f is a \" + obj.getClass().getName());\r\n\r\n  } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {\r\n\r\n\r\nSystem.out.println(e);\r\n\r\n  }\r\n    }\r\n}\r\n<\/pre>\n<p>\n<b>Output:<\/b><\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\">\r\n<code style=\"color: black; word-wrap: normal;\">In ripenFunc, t is a methodoverloading.Tomato\r\nIn sliceFunc, f is a methodoverloading.Fruit\r\nIn ripenFunc2, t is a methodoverloading.Tomato\r\nIn sliceFunc2, f is a methodoverloading.Tomato\r\nIn ripenFunc, t is a methodoverloading.Tomato\r\nIn sliceFunc, f is a methodoverloading.Fruit\r\nIn ripenFunc2, t is a methodoverloading.GreenZebra\r\nIn sliceFunc2, f is a methodoverloading.GreenZebra<\/code>\r\n<\/pre>\n<p>&nbsp;<br \/>\nThis was an example of how to create and use copy constructors in Java.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an example of how to create a copy constructor in a class.\u00a0We have set the example, in order to demonstrate the copy constructor and its use between classes and their subclasses following the steps below: We have created FruitQualities class, Seed class and Fruit class, that all have copy constructor.\u00a0 We have also &hellip;<\/p>\n","protected":false},"author":6,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[100],"tags":[1081,189],"class_list":["post-221","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-class","tag-class","tag-core-java-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Copy Constructor example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This is an example of how to create a copy constructor in a class.\u00a0We have set the example, in order to demonstrate the copy constructor and its use\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Copy Constructor example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This is an example of how to create a copy constructor in a class.\u00a0We have set the example, in order to demonstrate the copy constructor and its use\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-11T19:22:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-07-21T22:09:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Byron Kiourtzoglou\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Byron Kiourtzoglou\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/\"},\"author\":{\"name\":\"Byron Kiourtzoglou\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/3b111ec1048740c68c9e709ff6240015\"},\"headline\":\"Copy Constructor example\",\"datePublished\":\"2012-11-11T19:22:23+00:00\",\"dateModified\":\"2013-07-21T22:09:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/\"},\"wordCount\":285,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"class\",\"core java\"],\"articleSection\":[\"class\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/\",\"name\":\"Copy Constructor example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2012-11-11T19:22:23+00:00\",\"dateModified\":\"2013-07-21T22:09:26+00:00\",\"description\":\"This is an example of how to create a copy constructor in a class.\u00a0We have set the example, in order to demonstrate the copy constructor and its use\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"class\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/class\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Copy Constructor example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/3b111ec1048740c68c9e709ff6240015\",\"name\":\"Byron Kiourtzoglou\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Byron-Kiourtzoglou-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Byron-Kiourtzoglou-96x96.jpg\",\"caption\":\"Byron Kiourtzoglou\"},\"description\":\"Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications\/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.\",\"sameAs\":[\"https:\/\/www.pivotalgamers.com\/\",\"https:\/\/www.linkedin.com\/in\/byron-kiourtzoglou-530ab222\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/byron-kiourtzoglou\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Copy Constructor example - Java Code Geeks","description":"This is an example of how to create a copy constructor in a class.\u00a0We have set the example, in order to demonstrate the copy constructor and its use","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/","og_locale":"en_US","og_type":"article","og_title":"Copy Constructor example - Java Code Geeks","og_description":"This is an example of how to create a copy constructor in a class.\u00a0We have set the example, in order to demonstrate the copy constructor and its use","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2012-11-11T19:22:23+00:00","article_modified_time":"2013-07-21T22:09:26+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Byron Kiourtzoglou","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Byron Kiourtzoglou","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/"},"author":{"name":"Byron Kiourtzoglou","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/3b111ec1048740c68c9e709ff6240015"},"headline":"Copy Constructor example","datePublished":"2012-11-11T19:22:23+00:00","dateModified":"2013-07-21T22:09:26+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/"},"wordCount":285,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["class","core java"],"articleSection":["class"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/","name":"Copy Constructor example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2012-11-11T19:22:23+00:00","dateModified":"2013-07-21T22:09:26+00:00","description":"This is an example of how to create a copy constructor in a class.\u00a0We have set the example, in order to demonstrate the copy constructor and its use","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/class\/copy-constructor-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"class","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/class\/"},{"@type":"ListItem","position":5,"name":"Copy Constructor example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/3b111ec1048740c68c9e709ff6240015","name":"Byron Kiourtzoglou","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Byron-Kiourtzoglou-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2013\/10\/Byron-Kiourtzoglou-96x96.jpg","caption":"Byron Kiourtzoglou"},"description":"Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications\/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.","sameAs":["https:\/\/www.pivotalgamers.com\/","https:\/\/www.linkedin.com\/in\/byron-kiourtzoglou-530ab222"],"url":"https:\/\/examples.javacodegeeks.com\/author\/byron-kiourtzoglou\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}