Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the timing of the upward transformation of java?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the timing of java upward transformation". the explanation in this article is simple and clear, easy to learn and understand. please follow the ideas of Xiaobian and go deep into it slowly to study and learn "what is the timing of java upward transformation" together!

1. Direct assignment

public static void main(String[] args) { //parent class reference refers to object referenced by child class reference Animal animal = new Cat();;//Upshift}

2, method parameters, a Cat subclass to an Animal type parent class, here is also able to take place upward transformation.

public class Test extends TestDemo { public static void func(Animal animal) { } public static void main(String[] args) { //parent class reference refers to object referenced by child class reference Cat cat = new Cat(); func(cat); }}

3, method return, func method return type is Animal, but the return is indeed a Cat type, here is also an upward transition.

public class Test extends TestDemo { public static Animal func() { Cat cat = new Cat(); return cat; } public static void main(String[] args) { Animal animal = func(); }} Thank you for reading, the above is the content of "what is the timing of java upward transformation", after studying this article, I believe that everyone has a deeper understanding of what is the timing of java upward transformation, and the specific use situation needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report