Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the concept of java's downward transformation?

Shulou Source: shulou.com Published: 2022-05-31 10:48:36 09月23日 Update

Today, the editor will share with you the relevant knowledge of what the concept of downward transformation of java is. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Concept

1. The downward transformation is the transformation of the parent object into the 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. The format is

Subclass object = (subclass) parent class instance

Be careful

Forced type conversion must be carried out when making a downward transition.

Example

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 be cast}} this is all about the article "what is the concept of java's downward transformation". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Tags: Subclasses knowledge articles types concepts objects that is content instances mandatory different large most time more format current knowledge points industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Microsoft Docker vpn NVidia