#27 Kotlin Tutorial | Constructor

preview_player
Показать описание


Follow on Facebook:

Subscribe to our other channel:
Telusko Hindi :
Рекомендации по теме
Комментарии
Автор

Actually if you add var/val before typeParameter in primary constructor, you are creating a field in class. Now what you have done is actually created 2 fields n and name which has the same value.
If you want primary constructor's parameters not to be a field of class then you should remove the var keyword.
class Human( var n: String) vs class Human( n: String )

SuperHarsh
Автор

You dont need to write | class Human constructor, you can write : class Human(val name : String){...and then you also dont need to use var name : String = n, you can in the main function do this:

val navin = Human("Navin")

println(navin)

BURAXON
Автор

This is the weirdest constructor syntax out of all the languages I know (C++, Java, Swift)

Knuckler
Автор

sir, for android interviews how to i prepare myself? please make a video on this

kcppp
Автор

hello sir how to take input value from user in

vikaspatil
Автор

I'm here for 1 second and I'm being called an alien

crayoneater.
Автор

bhai are you going to talk about super in the next video ? you should speak about it, its very important new kotliners. And for knowledge purpose kotlin never had support for secondary constructors out of the box, it was in milestone 11 release.

mohammadrehankodekar
Автор

so basically I had had to extend a webview and had to pass an context in super but I had to declare 2 constructors the primary constructor as well with the keyword separately because of the super keywords. sharing the code might help you understand what I mean to say.

mohammadrehankodekar