Home >Java >Javagetting Started >What is constructor function in java

What is constructor function in java

(*-*)浩
(*-*)浩Original
2019-11-12 09:48:397256browse

What is constructor function in java

The constructor is a member of the object-oriented system. The constructor can be called a constructor. Its function name is the same as the class name. There is no need to define a return value type and no specific The return value.

The constructor is a function called when building a created object. Its function is to initialize the object. All objects created must be initialized through the constructor. (Recommended learning: java course)

If there is no constructor defined in a class, then the class will have a default empty parameter constructor. If a specified constructor is defined in a class, there is no default constructor in the class.

What is constructor function in javaWhat is constructor function in java

#When describing a thing, the thing already has some content that already exists. When these contents are defined in the constructor, the constructor can be defined.

There can be multiple constructors in a class that can initialize different objects differently. The presence of multiple constructors in a class is called overloading.

Overloading is in a class, the method name is the same, but the parameters are different. The return types can be the same or different. The overloaded methods must have different formal parameter lists, parameter numbers or types. Overloaded methods can be overloaded in the same class or in a subclass

What is constructor function in java

The difference between general functions and constructors:

When the constructor creates an object, it calls the corresponding constructor and the object is initialized. When an object is created, the constructor is called only once.

Because the constructor is named the same as the class name, the first letter must be capitalized; generally, after the function object is created, it is called only when the function function is needed. After the object is created, general functions can be called multiple times. The first letter of the general function name is lowercase

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

Statement:
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
Previous article:What is a process in javaNext article:What is a process in java