Answers for "constructors vs blocks"

0

constructors vs blocks

constructor: instance of the class.
			private constructor (Driver class)  ==> singleton class
			constructor can only be called within another constructor
	   	    constructor will be executed when the object is created
			can be overloaded cannot be overridden
		
		static block: belongs to the class
				 executed as soon as the class is loaded
				 only gets executed once.
				
		instance block:  belongs to the object
						gets executed when the object is created
						executed before constructor
Posted by: Guest on January-14-2021

Browse Popular Code Answers by Language