Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the timing of the upward transformation of java?

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

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!

Tags: Timing subcategory method type learning content object that is ideas situations articles more knowledge knowledge points articles follow questions practice push research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux MariaDB Shulou Technology OPPO Reno Apple