{"id":485,"date":"2021-01-07T16:33:28","date_gmt":"2021-01-07T16:33:28","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/?page_id=485"},"modified":"2021-01-07T16:54:17","modified_gmt":"2021-01-07T16:54:17","slug":"polymorphism","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/inheritance-polymorphism\/polymorphism\/","title":{"rendered":"Polymorphism"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a21c41f84298\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a21c41f84298\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/inheritance-polymorphism\/polymorphism\/#Assignment_of_Subclass_and_Superclass_Objects\" >Assignment of Subclass and Superclass Objects<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/inheritance-polymorphism\/polymorphism\/#Method_Parameters\" >Method Parameters<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/inheritance-polymorphism\/polymorphism\/#Subclass_and_Superclass_Objects_as_Method_Parameters\" >Subclass and Superclass Objects as Method Parameters<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/inheritance-polymorphism\/polymorphism\/#Secretary\" >Secretary<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/inheritance-polymorphism\/polymorphism\/#ExecutiveSecretary\" >ExecutiveSecretary<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/inheritance-polymorphism\/polymorphism\/#Manager\" >Manager<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/inheritance-polymorphism\/polymorphism\/#Executive\" >Executive<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/inheritance-polymorphism\/polymorphism\/#Programmer\" >Programmer<\/a><\/li><\/ul><\/nav><\/div>\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Assignment_of_Subclass_and_Superclass_Objects\"><\/span>Assignment of Subclass and Superclass Objects<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Consider our earlier <strong>Employees\/Managers<\/strong> example.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because class&nbsp;<strong>Manager&nbsp;<\/strong>is <em>a kind of<\/em>&nbsp;<strong>Employee<\/strong>, we can <em>refer to it<\/em> using the type <strong>Employee<\/strong> (<strong>staff[2]<\/strong>&nbsp;is of type&nbsp;<strong>Employee<\/strong>):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>staff[2] = new Manager(\"Mother Theresa\",\n                       120000,\n                       new Date(89, 3, 5),\n                       \"Demi Moore\");<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">but we&nbsp;<em>can&#8217;t<\/em>&nbsp;call <strong>Manager<\/strong>-specific methods through that reference:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>String sec = staff[2].getSecretaryName(); \/\/ Error<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Java gives a compilation error:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Error: Method getSecretaryName() not found in Employees.Employee<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If we know that it really&nbsp;<em>is<\/em>&nbsp;a&nbsp;<strong>Manager<\/strong>, then we can cast it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>String sec = ((Manager)staff[2]).getSecretaryName();<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">but if it really&nbsp;<em>isn&#8217;t<\/em>&nbsp;a&nbsp;<strong>Manager<\/strong>,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>String sec = ((Manager)staff[0]).getSecretaryName();<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">then Java throws an exception at run time:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>java.lang.ClassCastException<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s best to try to restrict this kind of casting only to within code that is hidden from the outside world!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In general, you can assign a <em>superclass<\/em> object to a <em>subclass<\/em> object:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Employee colleague = new Manager();<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">but not the other way around:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Manager colleague = new Employee(); \/\/ Error<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this case, Java gives a compile-time error:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Error: Incompatible type for vardeclaration.&nbsp;\n    Explicit cast needed to convert Employees.Employee \n    to Employees.Manager<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why?<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Method_Parameters\"><\/span>Method Parameters<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Subclass_and_Superclass_Objects_as_Method_Parameters\"><\/span>Subclass and Superclass Objects as Method Parameters<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">It is possible (and actually a very common practice) to declare a method with one or more parameters of&nbsp;<em>superclass<\/em>&nbsp;types, and then actually pass subclass objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, imagine that we had an expanded class hierarchy:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"530\" height=\"339\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/asssub1.gif\" alt=\"\" class=\"wp-image-491\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:28px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">We need to add some new classes to represent this new hierarchy:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Secretary<\/strong><\/li><li><strong>Executive<\/strong><\/li><li><strong>ExecutiveSecretary<\/strong><\/li><li><strong>Programmer<\/strong><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">and we also will make some modifications to the existing Manager class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Secretary\"><\/span>Secretary<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s class&nbsp;<strong>Secretary<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage company;\n\nimport java.util.Date;\n\npublic class Secretary extends Employee\n{\n    public Secretary(String n, double s, Date d, int ts)\n    {\n        super(n, s, d);\n    }\n    \n    public int getTypingSpeed()\n    {\n        return m_typingSpeed;\n    }\n    \n    public void setTypingSpeed(int ts)\n    {\n        m_typingSpeed = ts;\n    }\n    \n    \/\/\/\/\/\/\/\/\/\/\/\/ Data \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n    private int\tm_typingSpeed;\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"ExecutiveSecretary\"><\/span>ExecutiveSecretary<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s class&nbsp;<strong>ExecutiveSecretary<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage company;\n\nimport java.util.Date;\n\npublic class ExecutiveSecretary extends Secretary\n{\n    public ExecutiveSecretary(String n, double s, \n                              Date d, int ts)\n    {\n        super(n, s, d, ts);\n    }\n\n    \/\/ Other attributes of an Executive Secretary...\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Manager\"><\/span>Manager<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now, let&#8217;s make some changes to class&nbsp;<strong>Manager&nbsp;<\/strong>so it can refer to the&nbsp;<strong>Secretary&nbsp;<\/strong>object, rather than just use the name of secretary:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [7,10,22,23,24,25,26,27,28,29,30,31,32,33]; title: ; quick-code: false; notranslate\" title=\"\">\npackage company;\n\nimport java.util.Date;\n\npublic class Manager extends Employee\n{\n    public Manager(String n, double s, Date d, Secretary sec)\n    {\n        super(n, s, d);\n        m_secretary = sec;\n    }\n    \n    public void raiseSalary(double byPercent)\n    {\n        \/\/ Add 1\/2% bonus for every year of service\n        Date today = new Date();\n        double bonus =\n                0.5 * (today.getYear() + 1900 - getHireYear());\n        super.raiseSalary(byPercent + bonus);\n    }\n    \n    public Secretary getSecretary()\n    {\n        return m_secretary;\n    }\n    \n    public void setSecretary(Secretary sec)\n    {\n        m_secretary = sec;\n    }\n    \n    \/\/\/\/\/\/\/\/\/\/\/\/ Data \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n    private Secretary\tm_secretary;\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Executive\"><\/span>Executive<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s class&nbsp;<strong>Executive<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage company;\n\nimport java.util.Date;\n\npublic class Executive extends Manager\n{\n    public Executive(String n, double s, Date d, \n                     ExecutiveSecretary sec)\n    {\n        super(n, s, d, sec);\n    }\n    \n    public void raiseSalary(double byPercent)\n    {   \n        \/\/ Add 20% options bonus \n        double options_bonus = 20.0;\n        super.raiseSalary(byPercent + options_bonus);\n    }\n}\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Note the extra bonus in&nbsp;<code><strong>raiseSalary<\/strong><\/code>&#8230;<\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Programmer\"><\/span>Programmer<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">And finally, here&#8217;s class&nbsp;<strong>Programmer<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage company;\n\nimport java.util.Date;\n\npublic class Programmer extends Employee\n{\n    public Programmer(String n, double s, Date d,\n                      String&#x5B;] langs)\n    {\n        super(n, s, d);\n        m_languages = langs;\n    }\n    \n    public String&#x5B;] getLanguages()\n    {\n        return m_languages;\n    }\n    \n    public void setLanguages(String&#x5B;] langs)\n    {\n        m_languages = langs;\n    }\n    \n    \/\/\/\/\/\/\/\/\/\/\/\/ Data \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n    private String&#x5B;]\tm_languages; \/\/ Programming languages\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Test Program<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now, here&#8217;s a test program to use the new features:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage company;\n\nimport java.util.Date;\n\npublic class CompanyTest\n{\n    public static void main(String&#x5B;] args)\n    {\n        Employee&#x5B;] staff = new Employee&#x5B;6];\n\n        staff&#x5B;0] = new Employee(&quot;Charlie Chaplin&quot;, 34000,\n                                new Date(78, 7, 9));\n        staff&#x5B;1] = new Secretary(&quot;Demi Moore&quot;, 17000,\n                                new Date(95, 8, 16), 15);\n        staff&#x5B;2] = new ExecutiveSecretary(&quot;Florence Nightingale&quot;,\n                                50000, new Date(71, 4, 23), 150);\n        staff&#x5B;3] = new Manager(&quot;Mother Theresa&quot;, 0,\n                                new Date(89, 3, 5), \n                                (Secretary)staff&#x5B;1]);\n        staff&#x5B;4] = new Executive(&quot;Bill Gates&quot;, 42000000, \n                                new Date(90, 1, 1),\n                                (ExecutiveSecretary)staff&#x5B;2]);\n        String&#x5B;] languages = {&quot;Java&quot;, &quot;C++&quot;, &quot;C&quot; };\n        staff&#x5B;5] = new Programmer(&quot;Bryan Higgs&quot;, 250000,\n                                new Date(76, 4, 12),\n                                languages);\n\n        for (int i = 0; i &lt; staff.length; i++)\n            staff&#x5B;i].raiseSalary(5);     \/\/ by 5 percent\n\n        for (int i = 0; i &lt; staff.length; i++)\n            staff&#x5B;i].print();\n\n        Secretary sec = ((Manager)staff&#x5B;3]).getSecretary();\n        System.out.println(staff&#x5B;3].getName() + &quot;&#039;s secretary: &quot; \n                            + sec.getName());\n        sec = ((Executive)staff&#x5B;4]).getSecretary();\n        System.out.println(staff&#x5B;4].getName() + &quot;&#039;s secretary: &quot;\n                            + sec.getName());\n        Programmer prog = (Programmer)staff&#x5B;5];                    \n        System.out.println(prog.getName()\n                            + &quot; knows the following languages:&quot;);\n        String&#x5B;] langs = prog.getLanguages();\n        for (int lang = 0; lang &lt; langs.length; lang++)\n        {\n            if (lang != 0)\n                System.out.print(&quot;,&quot;);\n            System.out.print(langs&#x5B;lang]);\n        }\n        System.out.println();\n    }\n}\n\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">It produces the following output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Charlie Chaplin 35700.0 1978\nDemi Moore 17850.0 1995\nFlorence Nightingale 52500.0 1971\nMother Theresa 0.0 1989\nBill Gates 5.565E7 1990\nBryan Higgs 262500.0 1976\nMother Theresa's secretary: Demi Moore\nBill Gates's secretary: Florence Nightingale\nBryan Higgs knows the following languages:\nJava,C++,C<\/strong><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Assignment of Subclass and Superclass Objects Consider our earlier Employees\/Managers example. Because class&nbsp;Manager&nbsp;is a kind of&nbsp;Employee, we can refer to it using the type Employee (staff[2]&nbsp;is of type&nbsp;Employee): staff[2] = new Manager(&#8220;Mother Theresa&#8221;, 120000, new Date(89, 3, 5), &#8220;Demi Moore&#8221;); but we&nbsp;can&#8217;t&nbsp;call Manager-specific methods through that reference: String sec = staff[2].getSecretaryName(); \/\/ Error Java gives [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":61,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","_uag_custom_page_level_css":"","ocean_post_layout":"left-sidebar","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"ocs-course-topics-sidebar","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","footnotes":""},"class_list":["post-485","page","type-page","status-publish","hentry","entry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"ocean-thumb-m":false,"ocean-thumb-ml":false,"ocean-thumb-l":false},"uagb_author_info":{"display_name":"Bryan Higgs","author_link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/author\/bryan\/"},"uagb_comment_info":0,"uagb_excerpt":"Assignment of Subclass and Superclass Objects Consider our earlier Employees\/Managers example. Because class&nbsp;Manager&nbsp;is a kind of&nbsp;Employee, we can refer to it using the type Employee (staff[2]&nbsp;is of type&nbsp;Employee): staff[2] = new Manager(\"Mother Theresa\", 120000, new Date(89, 3, 5), \"Demi Moore\"); but we&nbsp;can&#8217;t&nbsp;call Manager-specific methods through that reference: String sec = staff[2].getSecretaryName(); \/\/ Error Java gives&hellip;","_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/comments?post=485"}],"version-history":[{"count":4,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/485\/revisions"}],"predecessor-version":[{"id":493,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/485\/revisions\/493"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/61"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/media?parent=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}