Home > Java > Javagetting Started > body text

Java functions - similarities and differences between constructors and member functions

王林
Release: 2019-11-30 16:37:47
forward
2431 people have browsed it

Java functions - similarities and differences between constructors and member functions

Similarities and differences between constructors and member functions

1. External call angle

Construction Functions can only be called when the object is created;

Member functions can only be called after the object is created and can be repeated.

Related video tutorial sharing: java video

2. Return value angle

The constructor does not need to return Value;

Member functions are optional.

3. Permission modifiers

The constructor can use any permission modifier;

The member function can also use any permission modifier.

4. Internal calls

The constructor can call member functions, but this member function is generally not treated as an object behavior;

Constructor function You can call the constructor, and this (parameter list) calls other constructors in the current class;

Constructors cannot call each other, it will recur infinitely and this(...) must be in the first sentence! Prevent value overwriting;

Member functions can call member functions, member functions cannot call constructors, but they can call new. (The constructor can have the same name as the member function!)

Recommended related articles and tutorials: Zero Basic Introduction to Java

The above is the detailed content of Java functions - similarities and differences between constructors and member functions. For more information, please follow other related articles on the PHP Chinese website!

source:csdn.net
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!