There are mainly the following types of method calls in JAVA:
1. Non-static methods
Non-static methods are methods without static modification. For calls to non-static methods, they are called through objects. The expression is as follows:
Object name.Method()
public class InvokeMethod{ public static void main(String[] args){ InvokeMethod in = new InvokeMethod(); in.t1(); } public void t1(){ System.out.printfln("t1"); }}
2. Call static Method
Static method is a method modified with static. The static method is called through the class name. The expression is as follows:
Class name.Method()
public class InvokeMethod{ public static void main (String[] args){ InvokeMethod.t2(); } public static void t2(){ System.out.println("static t2...."); }}
3. Calls between methods
Calls between methods are mainly how to call other methods within a method.
(1) Call other methods inside the static method
If in this class, the static method can directly call the static method, in addition to the main method, it can also be in the custom static method Direct call, if it is a non-static method in this class, it must be called through the object.
public class InvokeMethod{ public static void main (String[] args){ t2(); } public static void t2(){ System.out.println("static t2..."); } public static void t1(){ //静态方法调用非静态方法需通过对象来调用 //InvokeMethod in =new InvokeMethod(); //in.t2(); t2(); System.out.println("static t1"); }}
If a static method is not in a class, calling a static method in another class must pass
class name.static method();
If a static method calls a non-static method of another class in different classes, you need to import the package in the class and call it by creating an object.
(2) Internal calls of non-static methods
If in this class, non-static methods can directly call static methods and non-static methods; in different classes, non-static methods call other classes The static method needs to be imported by the package in the class, and needs to be called by the class name; in a different class, when the non-static method calls the non-static method of other classes, the package in the class needs to be imported, and it needs to be created by object to call.
Recommended tutorial: Getting started with java development
The above is the detailed content of How are functions (methods) called in java. For more information, please follow other related articles on the PHP Chinese website!

The article discusses various Java garbage collection algorithms (Serial, Parallel, CMS, G1, ZGC), their performance impacts, and suitability for applications with large heaps.

The article discusses the Java Virtual Machine (JVM), detailing its role in running Java programs across different platforms. It explains the JVM's internal processes, key components, memory management, garbage collection, and performance optimizatio

Java's Nashorn engine enables JavaScript scripting within Java apps. Key steps include setting up Nashorn, managing scripts, and optimizing performance. Main issues involve security, memory management, and future compatibility due to Nashorn's deprec

Java's try-with-resources simplifies resource management by automatically closing resources like file streams or database connections, improving code readability and maintainability.

Java enums represent fixed sets of values, offering type safety, readability, and additional functionality through custom methods and constructors. They enhance code organization and can be used in switch statements for efficient value handling.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft