Java summary on calling methods

Below, we have sorted and summarized the calling methods according to Java, and tested the relevant calling codes to learn.

Java methods are mainly divided into three types:

One is static method

This method is modified with static. This method does not need to be bound to a specific object; The second is the common method without static modification; The third is the construction method, which is mainly used to initialize the class.

Static methods can be called with a defined and instantiated object, or directly with a class name.

The instance method must be called with a defined and instantiated object.

Test output:

Static method output succeeded: Hello

A null pointer exception occurred while calling the instance method

Method code in Java dynamic call class

Using math class. getDeclaredMethod("sin",Double.TYPE); Access the specified method, where "sin" indicates that the name of the method to be accessed is sin, double Type indicates that the type of the entry parameter is double

Output results after operation

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>