Java questions
Hasan Kocaman
Talks about #softwaretesting #marketing #test #automationtest #java #selenium #appium
1) What are static blocks and static initalizers in Java ?
Static blocks or static initializers are used to initalize static fields in java. we declare static blocks when we want to intialize static fields in our class. Static blocks gets executed exactly once when the class is loaded
. Static blocks are executed even before the constructors are executed.
2) How to call one constructor from the other constructor ?
With in the same class if we want to call one constructor from other we use this() method. Based on the
number of parameters we pass appropriate this() method is called.
Restrictions for using this method :
1) this must be the first statement in the constructor
2)we cannot use two this() methods in the constructor