class Animal { private name:string; public Firstname:string; constructor(theName: string) { this.name = theName; this.Firstname=theName; } } class Tiger { function sample(){ Animal animalName=new Animal('Tiger'); document.body.innerHTML = animalName.name; } sample(); }
Hi, new to this typeScript here in the animal class. I created the name of a private variable that I used in the constructor of the class. Now, in the Tiger class, I created an instance of the Animal class and was able to access this private variable.
My question is in java, if we do this, we will get an error. But in typeScript (because typeScript supports oops), we get no error, moreover, it gives a value, how is this possible?
source share