you sir are one of the BEST youtube tutors i have ever seen, you should have tens of thousands of subscribers- best description of primary and secondary constructors- seriously!! keep up the good work
@SB-ox1co Жыл бұрын
Thank you very much for this video. Coming from Java I was confussed about constructors in Kotlin.
@Matematica_Aplicada2 жыл бұрын
Thank you very much! Nice explanation!
@Ari-1183 жыл бұрын
Thanks loved it!
@keshav6612 жыл бұрын
HI Belal. Thanks for sharing this knowledge. My doubt is, as you mentioned, we cannot have any logic written inside the primary constructor. If we need to write then it should be within init block but there are few things like calculating the volume which is done inside the body of the primary constructor directly rather than writing in init block. How is it possible??
@soma78912 жыл бұрын
Probably are you referring to the volume property, that's is possible because you can write code inside the getter or the setter, but that code is called only when the getter or the setter are called. With the initializer blocks you have the code - generally is used for multiple lines of code - executed when the objects are created using the class.
@zakariarada18564 жыл бұрын
Great video thanks bro keep on
@kishorramani0074 жыл бұрын
Hi While creating instance of class, Secondary constructor's parameters value is assign first then init block is executed then secondary constructor's body execute? Why like this? If the parameters value is assigned first then body's println should print but it's print after init block
@SimplifiedCoding4 жыл бұрын
init block is called after primary constructor. And if you are making a call to secondary constructor then, in this case secondary constructor will call primary constructor and then init block. But when you call secondary constructor, primary constructor is called in the first line only and hence init block is also called and then the secondary constructor body is executed. Hope you got it.
@kakyoin453511 ай бұрын
Thank you so much. After i finish this oop i will build my android!
@olahuuber55404 жыл бұрын
what is the use of multiple init block
@SimplifiedCoding4 жыл бұрын
Haha good question, I have not came across any practical scenario where I had to create multiple init blocks. And it is recommended to have only one init block of required. So I can say there is no use of it.
@kubux64264 жыл бұрын
Could you make video about kotlin multiplatform?
@SimplifiedCoding4 жыл бұрын
Yeah I have plans about it
@muskanyousaf204 жыл бұрын
1st 🥰Will Surelly watch These kotlin Toutorial 🙂 Thanks for the Toutorial Please Make a Video on Firebase Pushed Notifications #request
@anil8014 жыл бұрын
what is use/purpose of "lateinit" in Kotlin?
@SimplifiedCoding4 жыл бұрын
Purpose of what?
@anil8014 жыл бұрын
@@SimplifiedCoding sorry, type error..its what is use/purpose of "lateinit" in Kotlin?
@SimplifiedCoding4 жыл бұрын
For this scenario #1 you cannot assign a value to the variable while declaring it #2 as you cannot assign a value, you can use null as in kotlin you have to give a value while declaring a variable #3 If you give null its ok, but the problem is from now onwards everywhere you need to use null safety operator with that variable #4 you can use lateinit when you dont want to use null safety But it may case a null pointer exception because lateinit means you dont have the value now but you will give it later. And you do not need to use null safety with lateinit. But use it only when you are absolutely sure that it will not be null.
@bhuvneshvarma78434 жыл бұрын
Thanks for the video!Your one observation is wrong in secondary constructor example. You said "First init block is called,then secondary constructor is called and then secondary constructor will call primary constructor".Wrong.The init block is always called after the primary constructor. So first primary constructor is executed.Then immediately init block starts to execute.After init block , secondary constructor block starts to execute.
@SimplifiedCoding4 жыл бұрын
I think I said exactly what you are saying. Anyways I will watch the video. May be I said wrongly. 👍
@yotsusan_machi3 жыл бұрын
oooh so the constructor with body is like init block wow thanks for this amazing knowledge btw how to use secondary constructor for app development in android phone
@footballCartoon912 жыл бұрын
despite of the many implicit functionality of creating objects under the hood sometimes we are confused whether it is implicit or explicit
@vengateshm21224 жыл бұрын
So the order is Primary constructor Init block Init block Secondary constructor
@SimplifiedCoding4 жыл бұрын
No init block is called after primary constructor. And if you are making a call to secondary constructor then, in this case secondary constructor will call primary constructor and then init block. In any case primary constructor has to be called. And if you have multiple constructor then only the calling constructor will be called and then primary constructor and then init block. But when you call secondary constructor, primary constructor is called in the first line only and hence init block is also called and then the secondary constructor body is executed. Hope you got it.
@vengateshm21224 жыл бұрын
@@SimplifiedCoding yeah.thank you.
@jishnupdileep31432 жыл бұрын
👏🏻👏🏻👏🏻
@bilelrahmouni01 Жыл бұрын
thank you
@beypazariofficial Жыл бұрын
why indian people always have to use "sir" phrase in their comments? and why are they so formal? its just youtube
@denkling3 жыл бұрын
You should consider to become a teacher!
@ipvoodoo4 жыл бұрын
I didn't understand anything at all
@SimplifiedCoding4 жыл бұрын
Can you please be a little specific about what exactly you did not understand?
@richenjoshi70542 жыл бұрын
true
@rxtechandtrading2 жыл бұрын
mabey u dont understand because you have put no effort into learning this language..This man has perfectly described the concepts of primary and secondary constructors in Kotlin