1

00:00:00,930  -->  00:00:06,300
Well discussing your neighbors B-ble if you discuss tactic with him as a no let alone little bit more

2

00:00:06,300  -->  00:00:07,400
about them.

3

00:00:07,680  -->  00:00:12,900
We not only shut them all very relaxed and our student class to incorporate static variables.

4

00:00:14,590  -->  00:00:20,510
Like startlement that's to clear the books are also declared with the key word stocktake and it means

5

00:00:20,510  -->  00:00:28,890
that there's a topic to the class that is there independent of any instances of the class like Instance

6

00:00:28,890  -->  00:00:35,340
variables static variables are also declared directly with the necklace that is a class level.

7

00:00:35,340  -->  00:00:40,290
So you can declare them and methods and you will get compiler dollars if you declare them and Mather's

8

00:00:42,230  -->  00:00:46,370
also like Instance variables they get initialized with a default value.

9

00:00:46,430  -->  00:00:54,090
If they are not explicitly initialised not the static variable is declared with a public access modifier

10

00:00:54,480  -->  00:00:57,810
then any code that is external to the class can access it.

11

00:00:57,810  -->  00:01:03,870
We are that class in of course code inside the class can access it directly.

12

00:01:03,870  -->  00:01:09,180
Also if it has default access level we know that only classes within the same package can access that

13

00:01:09,180  -->  00:01:16,460
variable so just ecstatic my first class name followed by dot operator is used to access and this topic

14

00:01:16,460  -->  00:01:23,930
really was declared in that class since I think we're able to start a class they're also referred to

15

00:01:23,930  -->  00:01:25,530
as class variables.

16

00:01:26,590  -->  00:01:29,100
So there is only one copy of a static variable.

17

00:01:29,160  -->  00:01:38,020
But class that copy is shared across all objects of the class what this means is if one object updates

18

00:01:38,030  -->  00:01:43,610
the value of a static variable then all other objects will see the same object value.

19

00:01:44,360  -->  00:01:51,040
On the other hand with Instance variables we know that every object of the class gets its own copy of

20

00:01:51,130  -->  00:01:57,390
every instance variable declared in the class so instance variables hold values unique to each object

21

00:01:57,840  -->  00:02:00,020
but does nothing but the spirit of the object.

22

00:02:01,620  -->  00:02:07,290
Here's a simple example here we have the Student class with the static variable called Con which is

23

00:02:07,290  -->  00:02:08,740
initialized to zero.

24

00:02:09,240  -->  00:02:13,940
There are also three instances of the Student class named S1 S2 S3.

25

00:02:14,040  -->  00:02:21,730
So as one increments can then count will be 1 and 2 and 3 will see the same or better value 1.

26

00:02:21,740  -->  00:02:28,480
Now if S2 increments can then convert increment or to do an as one industry will also see the contract

27

00:02:28,500  -->  00:02:35,930
us to not count is declared with public modifier then any court extended to the Student class can also

28

00:02:35,930  -->  00:02:42,680
include incremented and that a better value will once again be visible to any court that is able to

29

00:02:42,680  -->  00:02:47,990
access the and variable so static variable values are truly global.

30

00:02:48,180  -->  00:02:55,470
That is there is only one copy of the static variable per class not come into accessibility of static

31

00:02:55,470  -->  00:03:00,910
variables within the class in which they are declared they're accessible from static method to defining

32

00:03:00,930  -->  00:03:07,300
the class as both of them are started with a class but since they're also shared across objects of the

33

00:03:07,300  -->  00:03:13,440
class they are also accessible from instance methods as well as concepts of the class.

34

00:03:15,200  -->  00:03:20,390
Although we discussed accessibility of instance and static variables from the different kinds of methods

35

00:03:20,690  -->  00:03:24,650
like static on instance then must all be some confusion.

36

00:03:24,670  -->  00:03:26,140
So to be 100 percent sure.

37

00:03:26,180  -->  00:03:32,260
Let's look at this example had the class to start degradable and one instance variable.

38

00:03:32,340  -->  00:03:38,760
We also have two methods one instance method and one static method an instance mother can access anything

39

00:03:38,820  -->  00:03:41,400
that is topic for instance.

40

00:03:41,430  -->  00:03:47,310
So as you can see the instance method can access the instance really the static variable and also the

41

00:03:47,310  -->  00:03:48,910
static method.

42

00:03:48,930  -->  00:03:54,970
So basically there is no restriction when it comes to instance methods nobody comes to a static method

43

00:03:55,300  -->  00:04:01,620
we know that it needs to stay away from anything to do with objects that so as you can see it can access

44

00:04:01,620  -->  00:04:08,310
the static variable as it is not object specific but we get a compiler error when it Kreiss to access

45

00:04:08,550  -->  00:04:15,860
either the instance variable or the instance method as their object specific however the final statement

46

00:04:15,860  -->  00:04:22,430
shows that it can access an instance method or even an instance variable enough object to that object

47

00:04:22,430  -->  00:04:25,550
reference that is perfectly fine.

48

00:04:25,550  -->  00:04:31,810
Like we see here the object can be an object of the same class in a static matter it is different.

49

00:04:32,930  -->  00:04:38,690
It is just that the static method cannot directly access any data related stuff declared in the scene

50

00:04:38,690  -->  00:04:46,250
class let's make a small enhancement below a student class example to this topic really both in action

51

00:04:47,150  -->  00:04:54,260
you can also find the biggest quote in the resources section let's in enhance our student example a

52

00:04:54,260  -->  00:04:55,480
bit more.

53

00:04:55,490  -->  00:05:00,220
Let's say we want to keep track of the number of student objects getting created.

54

00:05:00,710  -->  00:05:06,050
So there should be a counter which gets incremented every time a student object is created.

55

00:05:06,950  -->  00:05:10,590
Begin create the counter as a static variable.

56

00:05:10,640  -->  00:05:13,640
So let's create a static variable call student called

57

00:05:16,410  -->  00:05:29,020
Write topic and that's just naming does student count and let the default be zero and here in the constructor

58

00:05:29,790  -->  00:05:39,050
let's just say student called less bliss unlist just hard to get there for the student called

59

00:05:42,430  -->  00:05:43,370
does get student

60

00:05:46,610  -->  00:05:48,190
can actually make it static

61

00:05:54,190  -->  00:05:59,410
and let's just go into the Student class method and let's say

62

00:06:02,400  -->  00:06:14,720
number of students created so far and you can simply do this to that class name and get student

63

00:06:17,350  -->  00:06:24,960
which is a static method static methods can be worked directly with the class name.

64

00:06:25,050  -->  00:06:27,420
We already know that said.

65

00:06:27,840  -->  00:06:38,810
So let's just go ahead and compain her on it and it says number of students created so far is three

66

00:06:40,180  -->  00:06:49,990
and that's said Now can you guess what happens if it if we remove the static keyword Yes and also make

67

00:06:49,990  -->  00:06:51,500
this this.

68

00:06:51,790  -->  00:06:54,450
In this case it's an instance variable.

69

00:06:54,460  -->  00:06:56,680
So it is specific to the object.

70

00:06:57,010  -->  00:07:04,570
And when we increment it for each student object it just gets incremented from 0 to 1 and that's about

71

00:07:04,570  -->  00:07:04,930
it.

72

00:07:05,080  -->  00:07:11,230
So it is incorrect right so it's not going to keep track of the total number of students that are getting

73

00:07:11,230  -->  00:07:12,240
created.

74

00:07:12,670  -->  00:07:17,210
So it just keeps on incrementing from 0 to 1 and that's incorrect.

75

00:07:17,350  -->  00:07:24,850
So it has to be static and it's true we started and that's about it.
