What is a constructor and what does it do?
I'll answer
Earn 20 gold coins for an accepted answer.20
Earn 20 gold coins for an accepted answer.
40more
40more
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
评论(499)
Helpful(122)
Helpful
Helpful(2)

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.