1

00:00:01,200  -->  00:00:06,780
OK let's just go ahead and write some code on most of the stuff we have learned in the previous lesson

2

00:00:07,080  -->  00:00:08,500
about interfaces.

3

00:00:08,910  -->  00:00:12,630
OK so let's get started on let's create a new interface called a.

4

00:00:12,720  -->  00:00:18,010
So let's just use the same names we have used in the previous lesson.

5

00:00:20,370  -->  00:00:24,750
Let's add two methods for one.

6

00:00:27,450  -->  00:00:34,500
So these are two abstract methods and recall that we can omit the key words the modifiers public and

7

00:00:34,530  -->  00:00:37,520
abstract because they are implicit.

8

00:00:37,530  -->  00:00:40,700
OK so they are included by default.

9

00:00:40,740  -->  00:00:42,990
So let's just let me just say that.

10

00:00:43,290  -->  00:00:48,000
And at this fine and we will say we're in this new folder called interface which is created within com

11

00:00:48,000  -->  00:00:48,870
semantics Square.

12

00:00:48,910  -->  00:00:49,670
OK.

13

00:00:50,040  -->  00:00:50,340
OK.

14

00:00:50,340  -->  00:00:55,490
So let me just say right here you are Java.

15

00:00:56,010  -->  00:00:57,800
Now let's create a subclass.

16

00:00:57,810  -->  00:00:59,210
Let's implement this interface.

17

00:00:59,220  -->  00:01:11,370
But let's keep the class as an abstract class so it has to be abstract class it's name it as abstract

18

00:01:11,530  -->  00:01:12,500
.

19

00:01:13,930  -->  00:01:15,150
And it implements a

20

00:01:20,590  -->  00:01:21,860
out of the two methods.

21

00:01:21,870  -->  00:01:23,790
Let's just implement one off them.

22

00:01:23,940  -->  00:01:30,730
So let me just copy this code and here we are providing an implementation for the Barmouth.

23

00:01:30,990  -->  00:01:37,320
And so for the Fruma Third we are not providing any implementation in this abstract class since it's

24

00:01:37,320  -->  00:01:38,340
an abstract class.

25

00:01:38,340  -->  00:01:44,250
It need not provide implementation for any of the inherited abstract methods but here we are just providing

26

00:01:44,250  -->  00:01:45,140
for one of them.

27

00:01:45,150  -->  00:01:46,050
So the missive does

28

00:01:50,460  -->  00:02:01,860
not look miscreate as such another subclass of this class abstract it and let's call it does x.

29

00:02:02,250  -->  00:02:03,780
So this is a concrete class

30

00:02:12,210  -->  00:02:15,560
so it extends abstract a under-the implements a.

31

00:02:15,620  -->  00:02:20,530
It need not implement it because it's actually extruding abstract and abstractly intent in clemency

32

00:02:20,970  -->  00:02:23,200
but let's just leave it like this.

33

00:02:23,260  -->  00:02:25,560
Let's just say it does not have any body.

34

00:02:25,560  -->  00:02:31,840
And let's not have any code in the body.

35

00:02:31,940  -->  00:02:34,630
Now we also have a test class called desk.

36

00:02:35,310  -->  00:02:37,560
And here it is the main method.

37

00:02:37,550  -->  00:02:43,190
You now you can ignore this method get round and here we are instantiating the interface A which was

38

00:02:43,230  -->  00:02:47,110
a compilation error because interfaces cannot be instantiated.

39

00:02:47,120  -->  00:02:51,990
Recall that an interface can only be used as a reference type but not as an object.

40

00:02:53,100  -->  00:02:58,350
So the compilers and ADO do Senator.

41

00:02:58,380  -->  00:03:03,250
This is abstract because A is an interface and it cannot be instantiated.

42

00:03:03,450  -->  00:03:05,780
So let me change this to hex.

43

00:03:05,790  -->  00:03:13,920
So we are instantiating the concrete class X and we are invoking the two methods foo unbar and let's

44

00:03:13,920  -->  00:03:18,060
combine this now.

45

00:03:18,090  -->  00:03:24,260
Now it says X is not abstract which is true because X's concrete does not override the abstract motard

46

00:03:24,380  -->  00:03:24,740
.

47

00:03:25,020  -->  00:03:31,830
Right because we have not yet provided an implementation for the abstract matter with us for the abstract

48

00:03:31,830  -->  00:03:40,290
method bar we are inheriting a we are getting the free implementation for them both of them.

49

00:03:40,300  -->  00:03:41,060
Abstract.

50

00:03:41,100  -->  00:03:47,010
Because I have struck it has implemented bar and X's inheriting it so that's good enough.

51

00:03:47,220  -->  00:03:50,390
So for bar we have an implementation for bugs not for food.

52

00:03:50,400  -->  00:03:52,740
So let's provide that implementation.

53

00:03:52,740  -->  00:03:58,050
So let me just copy this.

54

00:03:59,100  -->  00:04:05,840
Change it to who make this class hag's and within X we are printing.

55

00:04:06,110  -->  00:04:11,580
For now everything should be fine.

56

00:04:13,320  -->  00:04:20,100
You go it's printing foo which is in Class X underspending bar motard the the message from bar which

57

00:04:20,100  -->  00:04:22,910
is an abstract.

58

00:04:23,940  -->  00:04:26,750
So the bottom of that definition was provided here.

59

00:04:26,910  -->  00:04:34,080
Even if this was if it was not implementing a hundred just an independent class an X is still extending

60

00:04:34,080  -->  00:04:35,930
abstract A.

61

00:04:36,090  -->  00:04:42,840
Even in this case it would still it could do X doesn't have to define but it would still use the bar

62

00:04:42,840  -->  00:04:46,740
defined in abstract so everything would work as it is working now.

63

00:04:46,800  -->  00:04:50,010
So we discuss this and the lesson in the previous lesson.

64

00:04:50,040  -->  00:04:55,740
So let me just compile and run it so it works the way it was working.

65

00:04:55,950  -->  00:04:59,140
So let me just say re-inserted.

66

00:04:59,210  -->  00:05:01,150
Now let's look at the diamond problem.

67

00:05:01,150  -->  00:05:03,670
We know that the diamond problem is not there in Java.

68

00:05:03,740  -->  00:05:05,200
So we already discussed it.

69

00:05:05,270  -->  00:05:12,010
And so we have a new interface called Beat and it also has this declaration the abstract method fool

70

00:05:12,020  -->  00:05:12,330
.

71

00:05:12,350  -->  00:05:18,800
He also has abstract motard food and let's just from X let's implement B.

72

00:05:18,830  -->  00:05:23,640
So we are doing implementing multiple interfaces here on both the interface and have the same method

73

00:05:23,830  -->  00:05:24,410
.

74

00:05:24,890  -->  00:05:32,270
And we there is no Diamon problem here because we are just inheriting method declaration but that actually

75

00:05:32,270  -->  00:05:37,230
meant the definition is that is provided here in the class X.

76

00:05:37,280  -->  00:05:40,760
So there is no chance of a diamond problem.

77

00:05:40,760  -->  00:05:43,140
So let me recompile this.

78

00:05:43,160  -->  00:05:44,550
I mean exactly.

79

00:05:44,630  -->  00:05:48,140
Everything is fine.

80

00:05:48,290  -->  00:05:52,610
No let's just go ahead and test the constants.

81

00:05:52,630  -->  00:05:54,470
Interface can have a constant.

82

00:05:54,470  -->  00:05:56,400
So what are we discussed about constants.

83

00:05:56,400  -->  00:05:58,730
Let's just go ahead and do it.

84

00:05:58,760  -->  00:06:01,700
So in a I mean just I add

85

00:06:05,840  -->  00:06:07,810
this variable called cloud.

86

00:06:07,850  -->  00:06:13,200
So implicitly It is actually a static final one.

87

00:06:13,230  -->  00:06:15,810
So actually let me just remove this.

88

00:06:15,810  -->  00:06:16,940
Let's compile this.

89

00:06:17,030  -->  00:06:21,190
So here it gives a compilation error.

90

00:06:21,200  -->  00:06:24,560
It says that Val in origin gives a compilation error.

91

00:06:24,560  -->  00:06:28,760
That's because the value variable is a static final variable.

92

00:06:28,790  -->  00:06:33,140
Iron is started quite and has to be initialized and that did not happen here.

93

00:06:33,140  -->  00:06:39,260
So let's go back to a and let's initialize it do you find.

94

00:06:39,830  -->  00:06:41,910
And let's go into this.

95

00:06:41,930  -->  00:06:44,270
X let me print that value

96

00:06:44,270  -->  00:06:51,710
.

97

00:06:53,840  -->  00:06:56,010
So now it's printing the value.

98

00:06:56,180  -->  00:07:02,390
So that's so we need we have to initialize it for sure if it is a variable we need to initialize it

99

00:07:02,420  -->  00:07:07,510
because it's static final and final values have to be initialized.

100

00:07:07,520  -->  00:07:11,260
Now let's do just the name clashing of the variables.

101

00:07:11,360  -->  00:07:13,060
If you recall we discussed this.

102

00:07:13,070  -->  00:07:14,930
So indeed our job also.

103

00:07:14,990  -->  00:07:16,890
To declare the same variable.

104

00:07:17,390  -->  00:07:23,690
But let's initialize it to a different value 42 and existing it accessing it.

105

00:07:24,110  -->  00:07:25,700
But we have to.

106

00:07:25,770  -->  00:07:32,810
It's you know we cannot simply compile javac does client because job does cry and we would use would

107

00:07:32,810  -->  00:07:38,890
instantiate this X introduced or entia instantiate x.

108

00:07:39,410  -->  00:07:46,800
But then I mean it really not recompile X because there is no change in x x remains the same.

109

00:07:46,880  -->  00:07:50,530
It's just that our only be has been changed.

110

00:07:50,680  -->  00:07:51,120
OK.

111

00:07:51,140  -->  00:07:51,940
So.

112

00:07:52,130  -->  00:07:54,870
So then we just compile it as a client.

113

00:07:55,020  -->  00:08:02,210
It would see if there is any change in x and x is not changed because it's it because we haven't made

114

00:08:02,210  -->  00:08:03,300
any change here.

115

00:08:03,380  -->  00:08:06,840
So we're just used up all classify loff x.

116

00:08:06,860  -->  00:08:09,020
And so we won't see any issue there.

117

00:08:09,050  -->  00:08:11,450
So there is no point just compiling test line.

118

00:08:11,540  -->  00:08:16,100
What we need to compile is X.

119

00:08:19,160  -->  00:08:19,420
OK.

120

00:08:19,430  -->  00:08:28,610
You see when we when we compile X then it was in our Edwar checking if there was any change in a or

121

00:08:28,640  -->  00:08:33,320
b or abstract a and b b we introduce this new statement.

122

00:08:33,320  -->  00:08:41,690
So a recombines beat and then it gave us this compilation error as a reference to what is ambiguous

123

00:08:41,690  -->  00:08:48,070
because we we now have rightly defined in both A and B and it has since it has the same name.

124

00:08:48,080  -->  00:08:51,830
It is ambiguous so we need to qualify it.

125

00:08:51,890  -->  00:08:55,760
So if you recall we need to qualify it like this so let's say we are accessing B.

126

00:08:55,820  -->  00:08:59,450
So now we can do this and it works fine.

127

00:08:59,480  -->  00:09:00,960
Let's recompile.

128

00:09:01,130  -->  00:09:02,000
Slide.

129

00:09:02,300  -->  00:09:07,610
That's your own test line and it prints 42 now.

130

00:09:07,670  -->  00:09:10,260
So because it we are accessing the 1 and B.

131

00:09:10,340  -->  00:09:18,860
So that's named plashing and let's instead of giving a literal 42 Let's actually assign the value 42

132

00:09:19,370  -->  00:09:21,520
by making him a method call.

133

00:09:21,530  -->  00:09:27,020
So we introduce this method called get around and test blind and all it does is simply write down the

134

00:09:27,020  -->  00:09:28,110
value 42.

135

00:09:28,370  -->  00:09:31,450
So it's just that the this is a different way of initializing it.

136

00:09:31,530  -->  00:09:36,140
And instead of later we are using a method call.

137

00:09:36,140  -->  00:09:44,880
OK so let me just go ahead and recompile just glide mean x.

138

00:09:45,140  -->  00:09:46,600
Let me recompile X

139

00:09:49,830  -->  00:09:57,100
and ask Klein which is not new direction and so it brings the same value.

140

00:09:57,170  -->  00:10:02,740
So so that's a different way of initializing a variable and interface.

141

00:10:02,750  -->  00:10:09,270
But normally you would just pro-white literally wouldn't be doing this kind of any initialization at

142

00:10:09,260  -->  00:10:11,420
least I have never seen it.

143

00:10:11,480  -->  00:10:15,860
So that's about a variable initialization and that's about it.

144

00:10:15,980  -->  00:10:22,550
And as simple exercise that I want to give you as extruding an interface so let's say I want you to

145

00:10:22,550  -->  00:10:23,250
do that.

146

00:10:23,270  -->  00:10:25,110
So just create a new interface.

147

00:10:25,110  -->  00:10:26,060
We have two interfaces.

148

00:10:26,090  -->  00:10:26,740
A and B.

149

00:10:26,750  -->  00:10:32,510
So go ahead and create a new interface called C and C should extend it.

150

00:10:32,890  -->  00:10:37,940
OK I can just add a new abstract method called foobar.

151

00:10:37,940  -->  00:10:42,890
So earlier we had foo on bottle separate but that's just go ahead and add a new method called foobar

152

00:10:42,910  -->  00:10:43,440
.

153

00:10:43,910  -->  00:10:47,870
And so that's an interface extending another interface.

154

00:10:47,870  -->  00:10:56,330
So C interface C is extending a notch adding a new metric or foobar and from X just implement see just

155

00:10:56,330  -->  00:11:03,020
do something like this and provide an implementation for foobar and all you can do is just simply print

156

00:11:03,020  -->  00:11:06,980
out how and edit print statement column X uncolored foobar.

157

00:11:07,040  -->  00:11:11,000
So just provide the method definition foobar within X so that's all I want you to do.

158

00:11:11,380  -->  00:11:17,540
And you can find a code hundred code and resources section and it will also include this new interface

159

00:11:18,560  -->  00:11:21,710
and that's about it.

160

00:11:21,700  -->  00:11:22,130
Farnol
