What are the differences between the constructors and methods?

Hello Everyone????

What are the differences between the constructors and methods?

Java constructors are used for initializing objects. During creation, constructors are called to set attributes for objects apart from this few basic differences between them are:

Constructors are only called when the object is created but other methods can be called multiple times during the life of an object.

Constructors do not have a return type, whereas methods have a return type, which can be?void?or any other type.

Constructors are used to setting up the initial state but methods are used to perform specific actions.

#Java #constructor #copyconstructor #methods #software #developer #programming #code #return #inheritance #encapsulation #OOPS #class #objects #data #types #Java23 #interview #FullStack #abstract #interface #overloading #overriding #public #private #protected #default #static #arraylist #list #set #map #hashmap #treeset

要查看或添加评论,请登录

社区洞察

其他会员也浏览了