Let's not look at the most fundamental class in Java because the object plus object glass is considered 2
as the mother of all. 3
And by that we mean that it is the superclass or her writing that is every class directly or indirectly 4
and implicitly extends the Object class. 5
For example we know that the user class is the top most class in our inheritance tree. 6
So use that class directly and also implicitly extends the Object class. 7
Who are the staff class also extends object but it does that in an indirect way. 8
The other use a class since object class is a fundamental class. 9
We know that it should be in the OR doglike package and there are two reasons for having the Object 10
class. 11
First one is that it acts as a polymorphic. 12
That is you can assign any Jawa object to a variable whose reference type is Object class Unadilla job 13
designers who create classes with methods that would pick any type that never existed when the first 14
produced Garces. 15
Second reason is it I think several code methods that are inherited by every class since the object 16
class is the most super class on some of these methods can be used directly or can be overridden while 17
others are Margret's whiner which means that they cannot be overridden. 18
Now let's look at some of the most frequently used methods in the Object class. 19
First one is the string method and as a name so just ignore it and say string representation of the 20
object. 21
And by default it includes the class name on some weird number as we can see here. 22
In the case of stuff class let me just show this in the code. 23
OK here we are creating a staff instance and we're simply printing out stuff got to string so we are 24
invoking the string method on the staff reference so then I ran it. 25
It just bends the staff class name followed by this weird number. 26
So let's just go back. 27
I come in from Effective Java. 28
Actually it recommends to always override that boosting matter. 29
And the reason is it is very useful for debugging and boosting is automatically in-road when the object 30
reference is passed to the system dot dot Pentlands me. 31
That is you don't have to invoke the string method explicitly. 32
The printed matter does it automatically. 33
The item also recommends that this mother children and all of the interesting information contained 34
in the object. 35
Let me also show this where the staff object in our class me just common default. 36
Let me just uncommon this display use that info which was used in one of the previous day. 37
So it's just going to the user class and the User class I'm HAVERTON this goosestepping matter. 38
Just don't worry about this and not in it's quality and notation under Chancellery want. 39
So the posting that there simply prints the data the attributes. 40
So this whole piece of code was previously inside that display user informatic. 41
So we are right we have it and disgusting method and this glue string method actually what right the 42
string method in the superclass in the object class which is the superclass of user and display in the 43
display use informatively or simply passing this object. 44
And then we pass this the print Ellenwood automatically invoke the string method it wanted this dark 45
blue string and at that instance this method would be invoked and this distinguished get printed. 46
So we had this entire string inside display use info earlier. 47
Now we are we have changed the implementation so that it would involve the two string matter. 48
So let me just go ahead and run this as you can see it is amending the user info on its printing border 49
attributes in the class. 50
Next is a hash code matter. 51
Undertreatment something called hash quote off an object which is basically the objects memory address 52
and hexadecimal one. 53
So two object differences pointing to the same object will have the same high score. 54
And as you can see here the staff object is being referenced by two object references on both of them 55
have identical hash codes and this method is supported for the benefit of hash tables which we will 56
discuss in the collections framework chapter. 57
Let's look at this method in code. 58
So here we have the staff instance and we are simply printing the hash code and then we are creating 59
a new area be able call staff. 60
And we are assigning the same reference to it. 61
So this way both of them refer to the same object. 62
And when we opened the hash code for staff too it should be same as staff as a hash court for stuff 63
. 64
So let me run this. 65
And as you can see both of them have the same high score. 66
Next is equal to murder. 67
And it compares two objects for equanimity and accrue if they are equal. 68
So it compares the object on which the matter is invoked to the object that just passed us argument 69
and by default this method uses the equality operator. 70
You may recall the equality operator when applied on object references would return accrue only if both 71
the object or Francis refer to the same object. 72
But sometimes two different objects may be logical equaling that is and how identical contents. 73
But they're still two different objects. 74
Like in the example shown here. 75
Here we have two different user objects which are initialized at the same ID and name. 76
So they are logically equal and on Indicus up just like Haast tables you would want to create such kind 77
of objects as equal. 78
In that case you would have to override the equals method thereby overwriting its default behavior of 79
using the equality operator. 80
In this example you could add an equals method in the User class as shown here here only ID field is 81
used as typically ID feels uniquely identify objects. 82
Note is that the user parameter has to be Doncaster KREM object to use a class in order to use the get 83
ID method as obviously Object class will not have this method. 84
Next is the get class metric and it is basically a final method. 85
And they did and something called a class object which encapsulates all the Mattei information about 86
the class that is a class off the object on which this method is in work and meta information would 87
include details like the class name superclass name method names and so on. 88
And we will discuss it in more detail when we get to the GBM in the next chapter. 89
Next to the clone method and it simply returns a copy of this object that is a clone of this object 90
. 91
And this matter is a protected matter and it must be overridden if we want to use its functionality 92
. 93
But let's not worry about it for now as we will look at it soon. 94
When discussing a concept called interfaces so that's about the object last. 95
There are a few other interesting methods but they're related to threads and will be discussed when 96
we get to concurrency. 97
Thank you