What are the similarities and differences between constructor method and set method in Java?

王林
Release: 2020-07-21 17:14:05
forward
4095 people have browsed it

What are the similarities and differences between constructor method and set method in Java?

Analysis of similarities and differences:

(Recommended tutorial:java introductory tutorial)

Similarities:

Both assign values to member variables.

Differences:

1. Timing of calling

The construction method is automatically called by the jvm when the object is created; the set method is manually called after the object is created.

(Video tutorial recommendation:java video tutorial)

2. The main body of the call

The construction method is automatically called by jvm; the set method is an object The name is called manually.

3. Number of calls

The constructor can only be automatically called once by the jvm when the object is initialized; the set method can be called multiple times.

The above is the detailed content of What are the similarities and differences between constructor method and set method in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
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!