1

00:00:01,110  -->  00:00:03,230
Let's not look at a very important topic.

2

00:00:03,420  -->  00:00:10,790
Access levels not really understand what packages are what classes are and also what members construct

3

00:00:10,790  -->  00:00:13,730
ridiculous like reliables methods and so on.

4

00:00:14,210  -->  00:00:20,090
But our main goal is to build very design software and for that there are certain design principles

5

00:00:20,960  -->  00:00:26,840
in the next lesson they will learn about one such design principal information hiding because a name

6

00:00:26,840  -->  00:00:30,270
suggests has something to do with hiding off information.

7

00:00:31,250  -->  00:00:35,470
For example women not want our variables to be accessed directly.

8

00:00:35,840  -->  00:00:38,540
That is we want to hide our variables.

9

00:00:38,540  -->  00:00:44,330
For instance if you recall our student example we were accessing the name variable in the Student class

10

00:00:44,420  -->  00:00:45,570
directly.

11

00:00:45,890  -->  00:00:51,810
And that is a bad practice as we will see when learning about information hiding So you talking about

12

00:00:51,810  -->  00:00:58,200
restricting access to some of the stuff like Redeemer's information hiding is about how to provide such

13

00:00:58,200  -->  00:01:00,980
restrictions on to achieve it.

14

00:01:00,990  -->  00:01:06,680
It uses the concepts that we learn in this lesson so let's go ahead and learn about access elements

15

00:01:08,880  -->  00:01:14,860
access limits basically help in providing restrictions on accessing classes on their members.

16

00:01:16,570  -->  00:01:22,390
For example when it comes to classes V.M. want a class to be accessible only to classes within the same

17

00:01:22,390  -->  00:01:23,620
package.

18

00:01:23,620  -->  00:01:29,440
That is we don't want our class to be accessible outside of it's package for example we may not want

19

00:01:29,440  -->  00:01:34,130
classes outside the package to create an instance of one particular class.

20

00:01:34,600  -->  00:01:39,550
That is we want the class to be instantiated only by classes in the same package.

21

00:01:39,550  -->  00:01:47,430
So that's a kind of restriction however in most cases you would want the class to be accessible to every

22

00:01:47,430  -->  00:01:48,600
other class.

23

00:01:48,600  -->  00:01:52,830
There is two classes in the same package as well as two classes outside of each package.

24

00:01:54,190  -->  00:02:00,910
And for this to happen you will include a key word called public in the class declaration and here is

25

00:02:00,910  -->  00:02:07,570
how it would be when used in the class declaration for basics to modeless hit public is referred to

26

00:02:07,570  -->  00:02:14,650
as an access modifier and it should come before the key word us now if you place it in between what

27

00:02:14,650  -->  00:02:17,870
class and the class name then you get a compiler error.

28

00:02:18,690  -->  00:02:20,700
In fact you cannot have anything in between.

29

00:02:20,710  -->  00:02:25,480
The key word class name so you use public modifier.

30

00:02:25,530  -->  00:02:28,420
If the accessibility of the class is public.

31

00:02:28,670  -->  00:02:32,510
But for the previous kids their accessibility is only within the package.

32

00:02:32,540  -->  00:02:36,700
We do not use any modifier So that's not the focus.

33

00:02:36,740  -->  00:02:41,330
So if you don't use any access modifier then it implies that the class is accessible only within the

34

00:02:41,330  -->  00:02:42,040
package.

35

00:02:43,060  -->  00:02:50,260
Also you know the title is accessibility for book classes as well as interfaces interfaces and important

36

00:02:50,260  -->  00:02:54,600
concepts like class and will be introduced when discussing object oriented concepts.

37

00:02:56,470  -->  00:03:01,620
Similitude there are certain restrictions when it comes to members of a class like reliables methods

38

00:03:01,660  -->  00:03:07,140
constrictors or even member classes or member interfaces which will be introduced later.

39

00:03:07,450  -->  00:03:14,200
Let's see what these distinctions are are one restriction is for a member of that class to be accessible

40

00:03:14,320  -->  00:03:19,630
only within the class in which it is defined that is outside of the class that members should not be

41

00:03:19,630  -->  00:03:20,390
accessible.

42

00:03:21,290  -->  00:03:26,720
For example you may want a variable to be accessible only within that class like an arts methods are

43

00:03:26,720  -->  00:03:30,280
constructors but not to any code outside of the class.

44

00:03:31,710  -->  00:03:36,480
This you would use an access modifier call when declaring the variable.

45

00:03:36,520  -->  00:03:38,840
It's not just that the member is private but across

46

00:03:41,380  -->  00:03:46,690
sometimes you may want a particular member to be accessible not only with the next class but also to

47

00:03:46,720  -->  00:03:49,130
other classes in the same package.

48

00:03:49,210  -->  00:03:55,270
For this we do not use any access Madhi where sometimes this access level is also referred to as package

49

00:03:55,270  -->  00:03:58,400
private as the accesses private with a package.

50

00:04:00,380  -->  00:04:06,010
We may also want a member to be accessible to all classes in the same package like in the previous case

51

00:04:06,020  -->  00:04:06,240
.

52

00:04:06,500  -->  00:04:12,570
But in any Sheean we may want that member to be accessible to all subclasses of its costs on those up

53

00:04:12,570  -->  00:04:18,560
classes maybe outside the package do some classes are not discussed and they will be introduced to encumbering

54

00:04:18,620  -->  00:04:21,590
inheritance which is an object oriented concept.

55

00:04:22,440  -->  00:04:23,110
So let's start with you.

56

00:04:23,110  -->  00:04:26,840
What's the process for now but not at this access level.

57

00:04:26,880  -->  00:04:35,060
You would have to use an access modifier called protected when declaring the variable finally be me

58

00:04:35,060  -->  00:04:40,520
I also want certain members of the class to be accessible to any court regardless of where the court

59

00:04:40,520  -->  00:04:41,420
is.

60

00:04:41,480  -->  00:04:45,510
There is a court maybe inside the package or outside the package too.

61

00:04:45,620  -->  00:04:50,990
So that's the public access level and you would use an access modifier called public when declaring

62

00:04:51,000  -->  00:04:58,310
that even know that anything declared with public Marty for being a class or interface or any of their

63

00:04:58,310  -->  00:05:05,720
members that particular member would become part of the API as any code outside the package can also

64

00:05:05,720  -->  00:05:06,500
access it.

65

00:05:07,570  -->  00:05:12,170
Just know that these access levels are ordered from most to least restrictive.

66

00:05:12,850  -->  00:05:19,030
So first one is most strict so as visibility of class member is only within that class.

67

00:05:19,030  -->  00:05:25,580
Similarly last one is at least a strip built as a class member is accessible to any quarter ourself

68

00:05:25,620  -->  00:05:32,670
all the money for our private and public are to use most of the time it is used relatively rarely and

69

00:05:32,940  -->  00:05:41,180
default package by what access is also commonly used but maybe not as much as private and public finally

70

00:05:41,180  -->  00:05:46,130
know that interface's also have members like we deal with some matters but it's not really about their

71

00:05:46,130  -->  00:05:47,840
accessibility for now.

72

00:05:47,980  -->  00:05:53,990
We will discuss when we get to interface's So as you can see when compared to classes and interfaces

73

00:05:54,260  -->  00:06:00,410
members of a class have two additional access level restrictions that is private unprotected restrictions

74

00:06:01,400  -->  00:06:06,190
public and default access levels apply to both classes as well as their members.

75

00:06:07,340  -->  00:06:12,310
Let's let's just discuss a little bit more about only private modifier as there is one point I would

76

00:06:12,310  -->  00:06:14,830
like to highlight regarding private modifier.

77

00:06:16,550  -->  00:06:20,660
Let's see hope private modifier is used with various methods.

78

00:06:20,980  -->  00:06:22,970
The same applies to other modifiers too.

79

00:06:23,170  -->  00:06:25,350
So you don't have to look at them explicitly.

80

00:06:26,940  -->  00:06:31,050
If you're declaring a variable that's private you would use a modifier private.

81

00:06:31,380  -->  00:06:37,580
So not this variable would be visible only with the next class also the private variables can be defined

82

00:06:37,580  -->  00:06:44,190
at class level on me or not matters live in any variable defined in a method that is a local variable

83

00:06:44,360  -->  00:06:50,210
is already private to the ometer so using public modified with a local variable will give you a compiler

84

00:06:52,120  -->  00:06:54,670
Similarly you can find a method as a pirate.

85

00:06:55,300  -->  00:07:00,640
Not that he had to modify a pirate cannot be specified in between the methods returned by the method

86

00:07:00,640  -->  00:07:01,330
name.

87

00:07:01,600  -->  00:07:06,620
It has to be specified before it might otherwise be get a compiler.

88

00:07:06,730  -->  00:07:09,170
You just cannot have anything in between the mattress.

89

00:07:09,180  -->  00:07:17,680
You can type on them that's name next is the point I wanted to highlight using private modifier implies

90

00:07:17,690  -->  00:07:18,190
that it is.

91

00:07:18,290  -->  00:07:23,190
But I work with a class not by weight to objects of its class.

92

00:07:23,210  -->  00:07:24,450
Let's look at an example.

93

00:07:26,560  -->  00:07:29,590
This is a stripped down version of our student class example.

94

00:07:29,740  -->  00:07:36,130
Here we have a student class variable ID declare that's private and disgress has two objects reference

95

00:07:36,130  -->  00:07:37,870
by variables S1 and S2.

96

00:07:38,660  -->  00:07:41,210
There is also the class course with its own object.

97

00:07:42,920  -->  00:07:50,200
Not you can see object Essman can access I'll be full of objects as to even though ideas by to s2.

98

00:07:50,720  -->  00:07:55,020
That's because objects of a class can access each other's private stuff.

99

00:07:57,060  -->  00:08:03,670
Hoher the class course or even its object cannot access the ID field of either student class or any

100

00:08:03,670  -->  00:08:04,810
of its objects.

101

00:08:05,700  -->  00:08:11,460
So once again if something is declared private It means it is private goods class or not but the objects

102

00:08:11,460  -->  00:08:18,400
of its class you may also recall that when introducing packages it was mentioned that one use of package

103

00:08:18,400  -->  00:08:26,240
is security so that you can see here by using access modifiers like private we restrict what parts of

104

00:08:26,240  -->  00:08:29,180
the code can be seen outside the class.

105

00:08:29,420  -->  00:08:31,540
And of course outside the package too.

106

00:08:32,180  -->  00:08:35,240
So that's the whole discussion on access modifiers.

107

00:08:35,510  -->  00:08:40,490
Our next as we mentioned earlier they will look at an important design principle called information

108

00:08:40,490  -->  00:08:46,970
hiding which is a tool by using access modifiers we would also look at a couple of important effective

109

00:08:47,180  -->  00:08:54,060
items in understanding information hiding post offical wedding information hiding he had them all with

110

00:08:54,060  -->  00:09:00,120
the student example that we talked earlier will be enhanced the enhancement will be based on what we

111

00:09:00,120  -->  00:09:05,130
learn and information hiding there we will be using access modifiers.

112

00:09:05,250  -->  00:09:08,060
And so you will see them in action in that demo.

113

00:09:08,380  -->  00:09:08,960
Thank you.
