1

00:00:01,080  -->  00:00:07,890
Next thing to understand with regards to inheritance is about what members of a superclass can be inherited

2

00:00:07,950  -->  00:00:09,430
by subclasses.

3

00:00:09,700  -->  00:00:15,690
And this is dictated by access modifiers defined for those members which is cost access modifiers when

4

00:00:15,690  -->  00:00:18,750
covering access levels and packages.

5

00:00:18,830  -->  00:00:23,650
They were discussing about how one class can access other classes members.

6

00:00:24,210  -->  00:00:30,110
But here we are talking about members that are inheritable except for one access modifier where that

7

00:00:30,120  -->  00:00:32,190
is the purpose that access modifier.

8

00:00:32,220  -->  00:00:38,310
There is no difference when it comes to accessing members of a class versus inheriting membership across

9

00:00:39,360  -->  00:00:44,880
Britain or discussed Perpich remembered in detail as we did not cover subclauses at that instant of

10

00:00:44,880  -->  00:00:50,360
time so protected modifier will be discussed in detail in this lesson.

11

00:00:50,370  -->  00:00:53,370
This is an important topic not the end of the discussion.

12

00:00:53,370  -->  00:00:57,910
I'm going to use some code to demonstrate this in the clearest possible way.

13

00:00:58,440  -->  00:01:03,690
So let's look at the actual money first on how they can affect inheritance undergrad also serve as a

14

00:01:03,690  -->  00:01:11,580
refresher to what we discussed earlier when other packages help and meaningfully organizing our classes

15

00:01:11,660  -->  00:01:12,110
.

16

00:01:12,310  -->  00:01:16,610
But as classes within a package will form similar kind of functions.

17

00:01:16,690  -->  00:01:22,530
Sometimes some of these classes may interact with each of them however sometimes they may not interact

18

00:01:22,530  -->  00:01:26,840
with each other but still provide a similar kind of functionality.

19

00:01:26,970  -->  00:01:34,290
So all of us think of classes in a package as one close knit family access modifiers that allow us to

20

00:01:34,290  -->  00:01:41,530
specify what data and behavior of a class is accessible to family members and non-family members or

21

00:01:41,750  -->  00:01:48,120
family members being classis in the same package while non-family members are process reciting outside

22

00:01:48,130  -->  00:01:49,510
of the package.

23

00:01:49,670  -->  00:01:57,030
We will use this notional homily to explain some of the stuff in this lesson on how to access modifiers

24

00:01:57,120  -->  00:02:03,570
which were discussed previously discussed private default and public modifiers as they don't behave

25

00:02:03,690  -->  00:02:06,630
any differently from our earlier discussion.

26

00:02:06,630  -->  00:02:11,430
The only difference is that protected Madhi where which is specific to inheritance and that we will

27

00:02:11,430  -->  00:02:19,320
discuss next facias private modifier a private member which can be a private mailable or a private matter

28

00:02:19,320  -->  00:02:28,440
of a superclass is never inherited by any subclass recalled that no class can ever access other classes

29

00:02:28,440  -->  00:02:29,460
play much at all.

30

00:02:29,850  -->  00:02:30,900
So no difference here.

31

00:02:30,930  -->  00:02:32,580
In the case of inheritance.

32

00:02:33,420  -->  00:02:39,990
Next is a member with default access level which means no explicit access modifier is used.

33

00:02:39,990  -->  00:02:43,630
Default means only classes in the same package can access it.

34

00:02:43,890  -->  00:02:46,790
That is only family members can access it.

35

00:02:47,010  -->  00:02:53,700
So with regards to inheritance a default member is inherited by only subclauses in the same package

36

00:02:53,820  -->  00:02:55,550
as the superclass.

37

00:02:55,650  -->  00:03:02,880
Also the subprocess can only let other family members to access the inherited members so it is correct

38

00:03:02,880  -->  00:03:09,570
to a major inheritance is involved or not a default member is never accessible outside the package.

39

00:03:09,570  -->  00:03:15,110
Next is public modifier public means anybody can access it or anybody can inherit it.

40

00:03:15,570  -->  00:03:21,090
If I inherited the inherited member can be accessed by anyone too that is.

41

00:03:21,120  -->  00:03:27,260
Anyone can access the inherited member by using the subclass name or subclass object.

42

00:03:28,360  -->  00:03:34,440
Nokomis interesting modifier that is specific to inheritance which is protected protected member has

43

00:03:34,440  -->  00:03:35,580
same access libellous.

44

00:03:35,580  -->  00:03:41,690
Default member but in addition it also provides special access to only subclasses.

45

00:03:41,730  -->  00:03:47,940
Outside of the package Supertech protected member is primarily for use only in subprocess outside the

46

00:03:47,940  -->  00:03:55,010
package ought to only family members on one or more of those family members can be subprocess to holler

47

00:03:55,100  -->  00:03:55,170
.

48

00:03:55,170  -->  00:04:01,770
One thing to remember is that the inherited protected member in a subclass should not be accessible

49

00:04:01,800  -->  00:04:09,300
to any non-family member that is any class that is not in the same package as the superclass should

50

00:04:09,300  -->  00:04:10,430
not access it.

51

00:04:10,440  -->  00:04:12,590
We are the boss.

52

00:04:12,630  -->  00:04:13,650
Hope that's clear.

53

00:04:13,920  -->  00:04:17,740
But let's look at code and everything should be clear after that.

54

00:04:18,960  -->  00:04:22,430
For the sake of convenience and browsers see it sometime.

55

00:04:22,590  -->  00:04:28,500
I'm going to show this to my and my Eclipse editor and we're going to use 5 classes spread across two

56

00:04:28,500  -->  00:04:30,390
different packages.

57

00:04:30,390  -->  00:04:36,570
The reason for using two different packages is to demonstrate inheritance across packages.

58

00:04:36,570  -->  00:04:43,420
That is how superclass in one package under subclasses can be in a different package the packages I've

59

00:04:43,430  -->  00:04:44,740
named as follows.

60

00:04:44,810  -->  00:04:48,090
One is Kondrat semantics Gweedore OOP Don't be one.

61

00:04:48,140  -->  00:04:49,250
And the second one is calm down.

62

00:04:49,250  -->  00:04:51,920
Semantics square dog OOP duck Pete.

63

00:04:52,520  -->  00:04:58,550
Previously the package name was Kondrat semantics griddata basics on basics of democracy was under Busiek's

64

00:04:59,090  -->  00:05:01,840
So there we were dealing with only language basic cities.

65

00:05:01,910  -->  00:05:04,260
So the package name was basics.

66

00:05:04,580  -->  00:05:10,130
But since we are dealing with object oriented programming I introduce this new package called OOP.

67

00:05:10,310  -->  00:05:18,380
OK and it has two packages P1 and P2 under five classes are under Java beyond our Java Sea one bit to

68

00:05:18,420  -->  00:05:23,890
unseat two class names ending with the suffix one going to the package be one.

69

00:05:23,900  -->  00:05:31,820
So even once even going to prevent the ones ending with do with the suffix do which is B to C to D going

70

00:05:31,820  -->  00:05:34,200
to the second package too.

71

00:05:34,280  -->  00:05:36,730
So now let's look at the first class.

72

00:05:36,890  -->  00:05:40,430
Are Java and de-classified different variables.

73

00:05:40,430  -->  00:05:45,680
So in this demonstration I'm just going to use variables to demand strict inheritance accessibility

74

00:05:45,680  -->  00:05:48,720
of inheritance but the same applies to methods also.

75

00:05:48,840  -->  00:05:54,080
And this way the words are declared as static members but it need not be static which means that static

76

00:05:54,080  -->  00:05:56,240
members are also inheritable.

77

00:05:56,300  -->  00:06:01,590
So the first variable has the access modifier private under his name just pirate member.

78

00:06:01,700  -->  00:06:06,530
The second one does not have any access modifier which means that it has default access level and it

79

00:06:06,530  -->  00:06:08,250
is named as default member.

80

00:06:08,300  -->  00:06:12,930
The third one is has protected access modified and it is nimblest protected member.

81

00:06:12,950  -->  00:06:14,400
The final one is public.

82

00:06:14,390  -->  00:06:18,250
Has public access modifier under it is named as public member.

83

00:06:18,570  -->  00:06:28,160
No see when dodgiest simply extends A-one OK and it demonstrates accessibility of members to the inherited

84

00:06:28,160  -->  00:06:29,450
members.

85

00:06:29,710  -->  00:06:32,210
Do job which is in a different package.

86

00:06:32,300  -->  00:06:33,230
Also extents.

87

00:06:33,260  -->  00:06:40,400
Even so if one is in one package under a subclass it is in a different package and do Java is just a

88

00:06:40,400  -->  00:06:41,170
regular class.

89

00:06:41,180  -->  00:06:49,190
It does not extend even understood regler regular class but it demonstrates accessibility of variables

90

00:06:49,220  -->  00:06:57,070
of members within A-one and doors that have been inherited in C so it also tries to access them and

91

00:06:57,110  -->  00:07:03,260
also in C to also be true that Java is also like beyond or Java.

92

00:07:03,410  -->  00:07:11,390
So it does not extend any class and B to C to out in the same package and it is also introduced just

93

00:07:11,390  -->  00:07:15,980
to show accessibility of variables in a run.

94

00:07:16,010  -->  00:07:23,170
And also the in and also to show how it can access variables that are inherited by C too.

95

00:07:23,810  -->  00:07:27,510
OK so let's just begin with the first one which is a direct member.

96

00:07:27,680  -->  00:07:36,260
So let's go to see one or Java and let me just uncommon this so C one is simply extending a one.

97

00:07:36,460  -->  00:07:38,650
And here we get a compilation error.

98

00:07:39,140  -->  00:07:43,600
When I holler what it is a feel A-one not direct memory is not visible.

99

00:07:43,820  -->  00:07:50,410
So we know that private members are always private to the class itself so they are not inheritable.

100

00:07:50,460  -->  00:07:54,050
I also they are not accessible from a different class.

101

00:07:54,200  -->  00:08:00,480
So that so that's why if you're going to be taught Java on the file uncomment does class.

102

00:08:00,530  -->  00:08:04,320
It says that one book pirate member is not accessible.

103

00:08:04,580  -->  00:08:08,050
And of course same would apply for them both.

104

00:08:08,050  -->  00:08:10,570
But once you do so on we don't have to test that.

105

00:08:10,980  -->  00:08:13,030
Now let's go into one.

106

00:08:13,070  -->  00:08:17,280
Let's try the next one which is default remember it's going to see.

107

00:08:17,360  -->  00:08:26,570
Let me uncomment this and as you can see we still have the completion error because see too and it went

108

00:08:26,560  -->  00:08:34,640
out in a different package and the default member which is defined and even is not accessible to because

109

00:08:34,640  -->  00:08:38,920
default member is accessible only within the same package as a win.

110

00:08:38,990  -->  00:08:42,870
So only to add to family members right.

111

00:08:43,790  -->  00:08:51,290
But if you're going to see one or Java as you can see in this document default member is X is inherited

112

00:08:51,310  -->  00:08:51,710
.

113

00:08:52,100  -->  00:08:55,600
That's because you run and it went out in the same package.

114

00:08:55,600  -->  00:08:59,590
And moreover the default member is accessed directly.

115

00:08:59,660  -->  00:09:05,570
Right inherited members can be accessed directly now from being under Jawa you can access.

116

00:09:05,570  -->  00:09:06,440
Default member.

117

00:09:06,440  -->  00:09:08,010
Why not a one.

118

00:09:08,240  -->  00:09:10,920
Because be run on are in the same package.

119

00:09:11,180  -->  00:09:16,880
But interesting thing is that you can also access the inherited members to an inherited de-funded member

120

00:09:17,150  -->  00:09:21,960
so you can access it YRC run also so both of these are possible.

121

00:09:22,980  -->  00:09:25,220
And next is protected member.

122

00:09:25,220  -->  00:09:31,840
So let's going to see to and as you can see the protected member is inherited by C too.

123

00:09:31,850  -->  00:09:38,810
Even though C is in a different package so it can access a protected member So that's the main benefit

124

00:09:38,810  -->  00:09:41,440
of declaring a variable as a protected right.

125

00:09:41,460  -->  00:09:47,080
If it can be accessed by any subclass under subclass need not be in the same package.

126

00:09:47,210  -->  00:09:54,650
Now that's going to be to do our Java and B cannot access the protected member in a one so protected

127

00:09:55,280  -->  00:10:01,000
protected member has protected access level and it cannot be accessed so we get this compiler error

128

00:10:01,000  -->  00:10:01,620
.

129

00:10:01,640  -->  00:10:08,060
Now if I uncomment the second statement which is trying to access protected member YRC too.

130

00:10:08,180  -->  00:10:15,230
So C to inherit protected member but it is still not accessible from B to and would be said that the

131

00:10:15,230  -->  00:10:19,970
reason for that is because BE2 is not a family member.

132

00:10:20,020  -->  00:10:22,220
Even so B is not in the same package.

133

00:10:22,250  -->  00:10:24,720
Even so we discuss that also.

134

00:10:24,980  -->  00:10:31,680
So let me just comment this back and let me go in to see what seaven.

135

00:10:31,730  -->  00:10:38,750
Also can inherit the protected member you know that I don't see when it went out in the same package

136

00:10:39,380  -->  00:10:41,170
back from B run.

137

00:10:41,630  -->  00:10:46,680
You can access a protected member also is like a default member right.

138

00:10:46,700  -->  00:10:53,000
It has the same access level on B when he went out in the same package so it can access protected member

139

00:10:53,000  -->  00:10:53,450
.

140

00:10:53,450  -->  00:10:59,210
It can also access the protected member YRC one so see if one is inheriting this protected member on

141

00:10:59,210  -->  00:11:05,130
it can access it and see do you know that is in a different package and it is inheriting protected member

142

00:11:05,140  -->  00:11:05,270
.

143

00:11:05,510  -->  00:11:12,480
But Beaven is able to access or was not able to access it YRC do but be one is able to do it.

144

00:11:12,520  -->  00:11:20,840
That's simply because A-one and B1 are on are one family and so that is that in the same package and

145

00:11:20,840  -->  00:11:25,460
Beaven has the privilege to access protected member even YRC.

146

00:11:25,880  -->  00:11:26,580
OK.

147

00:11:27,010  -->  00:11:32,180
And the final one as a public member and public ments.

148

00:11:32,300  -->  00:11:35,000
Anybody can access it and anybody can inherit it.

149

00:11:35,120  -->  00:11:38,550
So C-2 can access here directly.

150

00:11:38,750  -->  00:11:45,650
Which means you can inherit it and is able to access it directly and you also can access it from using

151

00:11:45,700  -->  00:11:48,490
A-one and also using C-2.

152

00:11:48,950  -->  00:11:56,240
So that's the benefit of being public so early that it was not able to access YRC to the protected member

153

00:11:56,240  -->  00:11:59,390
while you do but the public memory can access.

154

00:11:59,390  -->  00:12:03,070
So public is cruelly public it's part of the API.

155

00:12:03,260  -->  00:12:09,920
Now see one also can access a public member and be one also can access public members either using one

156

00:12:10,000  -->  00:12:11,460
or see one.

157

00:12:11,570  -->  00:12:13,300
So that's about it.

158

00:12:13,430  -->  00:12:20,660
The nice thing is we could also demonstrate not just our members that are inherited but also accessing

159

00:12:20,660  -->  00:12:25,620
those members and the non-stop Grothus also accessing those members.

160

00:12:25,940  -->  00:12:27,010
And that's it
