aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics and collections K&B pg 526 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics and collections K&B pg 526" Watch "Generics and collections K&B pg 526" New topic
Author

Generics and collections K&B pg 526

sweety singh
Ranch Hand

Joined: Dec 15, 2007
Posts: 49
hi.. i have a doubt in the following code:


// i did not understand "o instanceof Moof"... how come object IS A Moof... object is a superclass... and there is no Moof object assigned to 'o'..
thanks...
Ian Edwards
Ranch Hand

Joined: Aug 14, 2006
Posts: 107


Every object inherits the equals() method from the Object class. You can then override it to carry out whichever equality tests are required for the class.

What this means is that you must use the same method signature as the Object class. This isn't a problem as every class extends from the Object class therefore every object IS-A Object. Even though the variable o is declared as being of type Object it is still a Moof object. However, in order to access any Moof members you need to first cast it to a Moof object.

Before you try treating o as a Moof object you must first check that it is indeed a Moof object. If it was for example a Dog object and you try accessing a Moof method you would get a ClassCastException.
sweety singh
Ranch Hand

Joined: Dec 15, 2007
Posts: 49
thanks...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics and collections K&B pg 526
 
Similar Threads
Want hepl to understand Implementin an equals()
instanceof
instance of problem
Doubt about instanceof operator
Not able to understand the program