1

00:00:01,080  -->  00:00:07,230
Next let's look at another widely used marker interface called Honorable from the Java dot land package

2

00:00:07,230  -->  00:00:07,720
.

3

00:00:08,010  -->  00:00:14,640
Even several classes in July that you package do implement Grown-Up an interface by implement inclinable

4

00:00:15,030  -->  00:00:18,570
class declares that its objects can read and their clients.

5

00:00:18,630  -->  00:00:25,410
That is there copies but copy we mean a duplicate object is written which would have the same state

6

00:00:25,410  -->  00:00:27,330
as the original object.

7

00:00:27,870  -->  00:00:31,330
But question is Where does this GRONING capability come from.

8

00:00:31,650  -->  00:00:37,940
Simply implementing Markin interface cannot magically do this whether the clone method in Object class

9

00:00:37,940  -->  00:00:42,980
is just the briefly mentioned does matter while discussing Object class.

10

00:00:43,200  -->  00:00:45,290
And we said that we will discuss it later.

11

00:00:45,690  -->  00:00:47,470
So let's look at it now.

12

00:00:48,510  -->  00:00:52,970
But convention tuneable functionality is implemented in this way.

13

00:00:53,130  -->  00:00:57,170
The class obviously should implement the marketing disclosable.

14

00:00:57,740  -->  00:01:00,820
Then you need to provide a method that supports cloning.

15

00:01:01,260  -->  00:01:03,290
Convention is to name the method as clone.

16

00:01:03,480  -->  00:01:04,890
But you can do a different name.

17

00:01:04,900  -->  00:01:12,090
Do you need to invoke the clone method in object to us since it's a superclass when we look use in the

18

00:01:12,150  -->  00:01:18,570
supercooled the current method in Object class would actually do all the heavy lifting on it and a copy

19

00:01:18,570  -->  00:01:20,130
of the object.

20

00:01:20,130  -->  00:01:26,490
However the copy it again would be of type Object and hence we need to cast it before returning it back

21

00:01:26,490  -->  00:01:27,920
to the caller.

22

00:01:28,020  -->  00:01:33,260
The clone method in Object class would check whether or not the current object implements global interface

23

00:01:33,270  -->  00:01:33,880
.

24

00:01:34,050  -->  00:01:36,930
If it does it would return a copy of the object.

25

00:01:36,990  -->  00:01:41,710
Otherwise it would throw an exception called Glue not supported exception.

26

00:01:42,150  -->  00:01:47,610
The Cricut end of that you see here and closing the method in location is related to handling of that

27

00:01:47,610  -->  00:01:48,990
exception.

28

00:01:48,990  -->  00:01:53,900
But let's not worry about it for now as we have not yet discussed exceptions.

29

00:01:53,920  -->  00:01:57,800
Note that if this method is not defined Bruening will just not work.

30

00:01:57,930  -->  00:02:03,480
Even if you have implemented Coonamble in the declaration you can simply end were blown metor on the

31

00:02:03,480  -->  00:02:09,300
object assuming it would directly involved the clone method in the object class that would not work

32

00:02:09,630  -->  00:02:16,180
as grown in Object class has protected access and hence can be invoked from only a subclass.

33

00:02:16,260  -->  00:02:22,260
So you need this kind of a method to support GRONING not that it's not necessary that you strictly have

34

00:02:22,260  -->  00:02:24,620
to invoke object classes clone.

35

00:02:24,690  -->  00:02:28,080
You're free to perform that cloning yourself.

36

00:02:28,080  -->  00:02:33,720
Finally the clone method performs what is called a shallow copy in order to generate a duplicate object

37

00:02:34,590  -->  00:02:40,440
shallow copy implies that when generating the new object defeating the origin an object or not Gloria

38

00:02:41,060  -->  00:02:41,330
did.

39

00:02:41,340  -->  00:02:46,990
Values are simply assigned to the corresponding fields in the new object had the fields been closed

40

00:02:46,990  -->  00:02:47,340
.

41

00:02:47,430  -->  00:02:50,390
Then we would call the process as deep copy.

42

00:02:50,580  -->  00:02:56,160
One problem that shall look up is that if a field is referencing a mutable object then Buddha origin

43

00:02:56,160  -->  00:03:00,390
an object as well as its clone would be referencing the same object.

44

00:03:00,420  -->  00:03:04,630
So if one of them modifies the mutable object then the other will also see the change.

45

00:03:04,680  -->  00:03:05,960
And that's not good.

46

00:03:06,270  -->  00:03:13,550
But if the fields are all primitives of reference in immutable objects then copy is not a problem.

47

00:03:13,590  -->  00:03:16,030
So if you know that there are any mutable objects.

48

00:03:16,030  -->  00:03:21,900
Then what you can do is once you get the grant from the superclass you can explicitly Glenda's in denial

49

00:03:21,900  -->  00:03:25,790
mutable objects and then read in the going back to the caller.

50

00:03:26,430  -->  00:03:32,130
Finally know that experts like Joshua Knoblock consider that it's a design flaw to have to enable as

51

00:03:32,130  -->  00:03:33,620
a marketing office.

52

00:03:33,780  -->  00:03:35,920
It would have been a mixing interface.

53

00:03:36,210  -->  00:03:42,150
As you can see the subclass is forced to implement a clone method in order to define the clone functionality

54

00:03:42,150  -->  00:03:43,050
.

55

00:03:43,050  -->  00:03:48,480
In that case why not have tuneable as a mixed in with gunas it's only meant that this is just because

56

00:03:48,480  -->  00:03:54,870
an item level in effective Java altered due to code the supplementary not for some relevant an interesting

57

00:03:54,870  -->  00:03:57,560
point on this topic.

58

00:03:57,710  -->  00:04:01,130
McGoohan very quick demo of the clone method.

59

00:04:02,070  -->  00:04:04,770
Here is a quote from the interview demo.

60

00:04:04,860  -->  00:04:11,370
You may recall that we have this class called X which was X turning abstract 8 I was also implementing

61

00:04:11,460  -->  00:04:13,460
three interfaces A B and C.

62

00:04:13,500  -->  00:04:17,930
So for this day I have introduced this global interface so it's implemented inclinable.

63

00:04:18,120  -->  00:04:24,110
And we also have this clone method which is exactly identical to what we have seen in this light.

64

00:04:24,260  -->  00:04:30,210
And so the goal is to create an instance an object of X and then invoke this method which would then

65

00:04:30,210  -->  00:04:34,430
return a clone off that object a duplicate of that object.

66

00:04:34,500  -->  00:04:36,130
So that is done from this method.

67

00:04:36,180  -->  00:04:37,550
This class desk.

68

00:04:37,830  -->  00:04:44,430
So here we are instantiating X and then here we are in working the clone method here the reference is

69

00:04:44,440  -->  00:04:45,940
C which is an interface.

70

00:04:45,960  -->  00:04:49,070
And it does not include the clone method.

71

00:04:49,170  -->  00:04:54,180
So that's the reason we have to downcast it we have to Buddhist typecast and then invoke the method

72

00:04:54,960  -->  00:05:02,310
and then the clone and then we get a clone object a clone and obviously that clone and the actual instance

73

00:05:02,310  -->  00:05:03,890
are two different instances.

74

00:05:04,050  -->  00:05:04,950
So they are not equal.

75

00:05:04,950  -->  00:05:07,040
And then this Gruinard should be brain.

76

00:05:07,260  -->  00:05:12,690
So let me just go ahead and compile and run this.

77

00:05:12,810  -->  00:05:13,530
So here it is.

78

00:05:13,530  -->  00:05:18,060
It goes on princedom grown created message that we see here.

79

00:05:18,060  -->  00:05:24,100
Now let me just go back to X. Let me comment this thing.

80

00:05:24,960  -->  00:05:31,840
If we are commandeers we need to get a clone non-supported exception because that's the check that not

81

00:05:32,060  -->  00:05:34,840
that that a clone method in the object class makes.

82

00:05:34,840  -->  00:05:38,900
So here we are invoking the going into object and that would make a check.

83

00:05:38,910  -->  00:05:46,480
And since Grown-Up it is not and is not implemented here we should get a trick or an exception.

84

00:05:46,530  -->  00:05:56,070
So the American public as you can see the clone method here in the object class is throwing this exception

85

00:05:56,070  -->  00:05:58,350
called clone non-supported exception.

86

00:05:58,410  -->  00:06:01,050
So that's that's what is being presented here.

87

00:06:01,090  -->  00:06:02,730
And that's about it.
