QuesHub > 函数 > 对象 > 时调 > ASK DETAIL

What is a constructor and what does it do?

Naomi Smith | 2023-05-05 12:30:35 | page views:1776
I'll answer
Earn 20 gold coins for an accepted answer.20 Earn 20 gold coins for an accepted answer.
40more

Noah Johnson

Works at IBM, Lives in Armonk.
Constructor is only called when you create a object. It is not called when you later only use your object somewhere. When you create a new object, a constructor is a method that is called and it initialize the variables/fields of an object. A constructor must have the same name as the class its in.
2023-05-10 12:30:35

Ava Brown

QuesHub.com delivers expert answers and knowledge to you.
Constructor is only called when you create a object. It is not called when you later only use your object somewhere. When you create a new object, a constructor is a method that is called and it initialize the variables/fields of an object. A constructor must have the same name as the class its in.
ask:3,asku:1,askr:137,askz:21,askd:152,RedisW:0askR:3,askD:0 mz:hit,askU:0,askT:0askA:4