Home  >  Article  >  Java  >  What is the definition and difference between static methods and non-static methods in Java?

What is the definition and difference between static methods and non-static methods in Java?

WBOY
WBOYforward
2023-04-22 12:34:081811browse

Concept

1. The method modified by static is a static method. Static methods do not need to be called by instance objects and can be called directly using Class.method. For example, LocalDate.now() provided by JDK8 is a typical static method, which returns the current time

2. Non-static methods are common methods without static, which usually require the object to be initialized before calling. The above validate and getValue are non-static methods that are called after instantiating the User object

Instance

    public static LocalDate now() {
        return now(Clock.systemDefaultZone());
    }

What are the basic data types of java

Java Basic data types are divided into:

1. Integer type, used to represent the data type of integers.

2. Floating point type, a data type used to represent decimals.

3. Character type. The keyword of character type is "char".

4. Boolean type is the basic data type that represents logical values.

The above is the detailed content of What is the definition and difference between static methods and non-static methods in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete