Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

28. Instance Initialization Block (IIB)

Welcome to this Session

Welcome

Greetings from MERCY Technologies

Overview

As part of this Session

1. Why we need IIBs?

2. When do IIBs execute?

3. Multiple IIBs

4. Some Important Points

As part of this Session

Diving

in-depth

1. Why we need IIBs?

1. Why we need IIBs?

1. Instance initializer block is used to initialize the object same as constructors

2. ie Instance Initializer block is used to initialize the instance variables

3. Just like constructors, IIBs also can be used to write the logic of the program which has to be executed automatically for all objects during their creation.

4. IIB is used to execute some pre-processing things for all objects as immediate when its created.

5. Because IIBs are executed whenever the object of any kind is created. so, if we want to write a logic which we want to execute on the creation of all kinds of objects, then using instance blocks is a good idea to avoid writing the same logic inside every constructor.

3. Multiple IIBs

1. A class can have any number of IIBs

2. If Multiple IIBs are there, then it will be executed from top to bottom one by one

3. Multiple IIBs

Important Points about IIBs

4. Important Points

1. IIB will be executed only once for each object creation.

2. IIBs are typically placed above the constructors within braces.

3. IIBs can be placed anywhere inside the class

4. It is not at all necessary to include IIBs in your classes.

2. When do IIBs execute?

1. Initializer block contains the code that is always executed whenever an instance is created.

2. IIBs executed every time when a new instance is created.

2. When do IIBs execute?

Learn more about creating dynamic, engaging presentations with Prezi