Java Tutorials: Initialization Block in Java

preview_player
Показать описание
Initialization Block in Java: It's a block of code.

Instance Initialization Block:
- They are related to object, Whenever a object is created, It get intialized.
- Instance variables are unique to object, each object has its own copy
Static Initialization Block:
- They are class variables
- They are attached to class
- It'll execute only once, whatever number of objects you have
- Used to initilized the block code.

Do watch video for more info.

This problem is similar to following:
static Initialization Block in java,
instance Initialization Block in java,
Difference between instance & static Initialization Block,
What is static Initialization Block,
static Initialization Block,
instance,
static,
instance Initialization Block,
static Initialization Block,
how to use static Initialization Block java,
java tutorial,
coding simplified,
java

CHECK OUT CODING SIMPLIFIED

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 300+ videos. My account is Partner Verified.

★☆★ VIEW THE BLOG POST: ★☆★

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★

★☆★ SEND EMAIL At: ★☆★
Рекомендации по теме
Комментарии
Автор

Wow. You have a LOT of videos. These new ones are way more basic and fundamental than many of the fancier ones you already presented. I am gong to eventually spend a lot of time on this channel. It took a little getting used to your presentation and all, but I am there. I understand pretty much 100% of the stuff you are saying the first time, which to me is the Gold Standard in presentation.

jvsnyc
Автор

One thing you might want to mention here, when you have, in general, multiple overloaded constructors, the compiler acts as if you included all the instance initialization blocks in order, right at the top of any constructors you have that don't begin with a call to this(, , ) to call one of those other overloaded constructors, but after the relevant super( ) call. I think it is interleaved with any data members that you initialize in-line in the class definition. I'll go check now. Some people think it is just an interview question, but it affects how your code runs...I will watch the "Constructors in Java" tutorial, out-of-order, next.

jvsnyc
Автор

Thanks a lot and it really solved a year long doubt 😊

jarvisfriday
Автор

Why we need the instance initializer block since we can initialize the objects directly in the class

moayadal-falahi
Автор

could have added about the constructor sequence, otherwise it's informative content

deeproy
Автор

Bro u have to explain how a instance and static block works not the output we get when we use it. You are just correcting your coding instead of explaining how it works

mohdsameer