In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "what is the basic knowledge content of the downward transformation of Java", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the basic knowledge content of the downward transformation of Java" can help you solve your doubts.
1. Concept
The downward transformation is that the parent object is transformed into a subclass object. We give a reference of a parent class reference of type Animal to a reference of type Bird, which is a downward transformation.
2. Format
Subclass object = (subclass) parent class instance
3. Pay attention
Forced type conversion must be carried out when making a downward transition.
4. Instance class Animal {public String name; public void eat () {System.out.println (this.name+ "eating");}} class Cat extends Animal {} class Bird extends Animal {public int age; public void fly () {System.out.println (this.name+ "takeoff");}} public class Test extends TestDemo {public static void main (String [] args) {Animal animal = new Animal () Bird bird = (Bird) animal;// must cast}}
The significance of the downward Transformation of Java
At the beginning of learning Java, I didn't pay attention to the downward transformation. It has not been clear about the meaning and purpose of the downward transformation, but it is not clear that it will not, and the process of development will certainly not be expected.
In fact, upward transformation and downward transformation are both very important. Maybe we usually see more upward transformation, and upward transformation is also easier to understand.
But will it be silly to transform downwards? I'm going to use a subclass instance object. First, I generate a subclass instance to assign a value to the parent class reference, and then forcefully transfer the parent class reference down to the subclass.
Quote, isn't this superfluous? I don't transition up or down, just use subclass instances.
After reading this, the article "what is the basic knowledge of the downward transformation of Java?" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.