End this demo I'm going get the monster I feel hiding as well as the overall lighting effect that we 2
can. 3
How do you feel re-assignment in a subclass. 4
So this is a user or Jawa. 5
And here we have two instance variables. 6
One is ID and the other is user type. 7
So the idea for this comes from the previous run one of the previous demos. 8
It is initialized to 1. 9
And in the subclass staff we are really clearing ID and initializing it to in the support class it was 10
initialized to 1. 11
Now we also to introduce this new variable called user type and it is initialized to user unstaffed 12
or Djala. 13
We have introduced this constructor and here we are re initializing user type stuff. 14
OK. 15
And then use about Djala and new numerator called display user info has been added and it simply Prendes 16
all the user attributes in this guess. 17
There are only two attributes the ID and user type and it simply print them and then user does our job 18
which is a tester to us. 19
We are creating an instance of staff and a reference type is user and we are simply invoking the method 20
display user in for. 21
So let me just go ahead and run this. 22
And here for I.D. It prints 1 and for user type prints stuff. 23
So that's going to user. 24
So for I.D. It is simply printing the value that is here. 25
So it's not printing the real declared value in the subclass even though we are accessing the display 26
user in format they're using a staff reference. 27
So that's because the value is not overridden and ID when we access it here it will always try to access 28
the ID field in the same class. 29
So it's exactly like a static method. 30
If you recall from our demo and in the previous lesson where the static methods cannot be overridden 31
but only it can be hidden. 32
So even there it was always accessing the static method in the same class. 33
And that's exactly what is happening here. 34
But with regards to user type the values being reassigned here in the constructor. 35
And so we have only a single version of user type and we can see the overriding effect here. 36
And the staff is getting printed. 37
Now let's just as soon that this display user info method is installed on here it is inside the staff 38
class. 39
Let's just write it here and now for ID it's going to print. 40
Oh 41
you need to typecast us to staff. 42
There you go. 43
So for ID it is two and four user type it is once again staff. 44
So for I.D. It was accessing the local ID value here in the same class and it's printing too. 45
So that's about it.