Home > Java > JavaBase > body text

What are the methods in java

angryTom
Release: 2019-11-14 15:28:56
Original
6694 people have browsed it

What are the methods in java

What are the methods in java

Defining a complete class method requires six steps, that is, six major steps part. Because of the differences in these six parts, it can be roughly divided into 9 methods.

What are the methods in java

1. General method

2. Construction method

3. Method with no parameters and no return value.

4. Methods with no parameters and return values.

5. Methods with parameters and no return value.

6. Methods with parameters and return values.

7. Static method.

8. Non-static methods.

9. Abstract method.

The following are three more important methods:

1. Construction method:

The method name must be the same as the class name and can be 0, 1 or more parameters

No return value, including void

The default return type is the object type itself

Can only be used in conjunction with the new operator

2. Static methods and non-static methods

Methods with static modification are called static methods. If not, it is called a non-static method.

The main method we are most familiar with has static modification. This method is also the one I am least familiar with and cannot understand.

static methods are generally called static methods. Since static methods can be accessed without relying on any object, there is no this for static methods. Because it is not attached to any object, since there is no object, there is no such thing as this.

3. Abstract method

Abstract method: A method without a method body in a class is an abstract method.

Abstract methods must be implemented! That is, inherited. So the class he belongs to must be the parent class. There must be a subclass.

If a subclass does not implement the abstract method in the parent class, the subclass also becomes an abstract class!

Abstract methods must be overridden. From no method body to a specific method body.

Abstract classes cannot be instantiated.

php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!

The above is the detailed content of What are the methods in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!