Polymorphic inheritance

<p>I have a question about how to define a method from a subclass or a parent class. For example:</p><pre><br /><code>public class Thought<br />{<br /> //-----------------------------------------------------------------<br /> // Prints a message.<br /> //-----------------------------------------------------------------<br /> public void message()<br /> {<br /> System.out.println ("I feel like I'm diagonally parked in a " +<br /> "parallel universe.");<br /><br /> System.out.println();<br /> }<br />}<br /></code><br /></pre><p>And the child class is:</p><pre><br /><code>public class Advice extends Thought<br />{<br /> //-----------------------------------------------------------------<br /> // Prints a message. This method overrides the parent's version.<br /> //-----------------------------------------------------------------<br /> public void message()<br /> {<br /> System.out.println ("Warning: Dates in calendar are closer " +<br /> "than they appear.");<br /><br /> System.out.println();<br /><br /> super.message(); // explicitly invokes the parent's version<br /> }<br />}<br /></code><br /></pre><p>If I wanted to invoke method message from the main method, would I have to use <code>Thought.message</code>, or <code>Advice.message</code> since I used the super invoker. Does super.(method)() technically just copy and paste the parent method into the child method, allowing you to create an object of only the child?</p><br /><h2>Click here view more answers <a href="http://ift.tt/1WFroPo">http://ift.tt/1WFroPo</a></h2>

Nhận xét

Bài đăng phổ biến từ blog này

Align div to bottom of the page in bootstrap

Align elements inside an tag vertically

Javascript is unable to stop page loading