Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the basic knowledge contents of the downward transformation of Java?

Shulou Source: shulou.com Published: 2022-06-01 13:34:44 10月04日 Update

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.

Tags: Subcategories content examples knowledge objects types basics basic knowledge that is articles clarity meaning learning coercion propriety importance superfluity no a little more ideas. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia macOS Shulou Technology Huawei