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

Example Analysis of Polymorphic Polymorphic in Java

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

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of polymorphic Polymorphic in Java, which is very detailed and has certain reference value. Friends who are interested must finish it!

# Polymorphism of method

Method override: the subclass overrides the method of the parent class, Override

Polymorphism:

For a certain type of method call, the method that is actually executed depends on the actual type of method at run time

When a method is called on a type, the method executed may be an override method of a subclass

Allow you to add more types of subclasses to extend the functionality

# keyword final

The method modified by final cannot be Override

Final-decorated classes cannot be inherited

Final-decorated field must be initialized when the object is created

Final-decorated fields cannot be reassigned after initialization

# method overloading

The main results are as follows: (1) the method name is the same, but the number, type and order of method parameters are different.

Method overloading requires two different things: the same method name and different parameter list in the same class.

# method overwrite / overwrite

When a subclass inherits all the member methods of the parent class that may be accessed by the subclass, if the method name of the subclass is the same as the method name of the parent class, the subclass cannot inherit the method of the parent class, and the subclass overrides the parent method.

(1) it means that the method of copying the parent class is mainly different from the parent class in the content of the method body.

# Class Polymorphism

Refers to the transformation that occurs in an inheritance relationship class between a subclass and a parent class.

Upward transformation: parent class object = subclass instance; / / automatic completion

Transition down: subclass subclass object = (subclass) parent class instance. / / forced completion

Public class Person {public void run () {System.out.println ("Person run");}}

Student

Public class Student extends Person {@ Override public void run () {System.out.println ("Student run");}}

Main

Public class Main {public static void main (String [] args) {Person s = new Student (); s.run ();}}

# important methods of Object

ToString serializes the instance

Equals determines whether two instances are logically equal.

HashCode calculates the hash value of an instance

The above is all the content of the article "sample Analysis of Polymorphic Polymorphic in Java". Thank you for reading! Hope to share the content to help you, more related knowledge, 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.

Share To

Internet Technology

Wechat

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

12
Report