Java-interface and polymorphism-

Source: Internet
Author: User

# #枚举只要switch (XX) inside the xx is an enumeration type, then the inside of the case only a few are already in the enumeration predefined variables can be selected,

Subclass to Parent class (upward transformation)

Parent class rotor class (downward transition) The parent class is the rotor class, sometimes it's OK, sometimes not, so you have to cast.

# #自己设置的实验

My doubts are: this hero address value and my sub-class Adhero address value is exactly the same, then why this hero can't see its sub-category of things, are the same address!!

According to personal understanding: Hero=adhero; The reference type of the hero on the left is different from the reference type of the right adhero. So why is it possible to assign Adhero to a different type of hero?

Since it is an assignment, it is clear that the child is assigned to the parent class. Why is it that the subclass goes to the parent class. Is it possible to translate the reference on a subclass into a reference to a parent class, and then copy it to hero, which seems to make sense, but strangely, from the printing result, the address that the parent refers to is exactly the same as the address referenced by the subclass. So what's the difference between this transition and the address referenced in the original book class?

============================================# #自己出的题parent class. Java

public class Hero {public String name = "来自父类的字段";public void effect(){System.out.println("来自父类的方法");}}

Child class. java

public class ADHero extends Hero {public String name = "来自子类的字段";public void effect(){System.out.println("来自子类的方法");}}

Test.java\

Java-interface and polymorphism-

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.