tag:blogger.com,1999:blog-7955003209126272036.post1185848136602777165..comments2024-02-23T23:16:22.861+05:30Comments on Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!: Do Interfaces really inherit the Object class in Java?Geekhttp://www.blogger.com/profile/00648920090539126396noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-7955003209126272036.post-46455897702004118392010-04-16T10:03:51.615+05:302010-04-16T10:03:51.615+05:30Thanks for a very nice article.
What if we conside...Thanks for a very nice article.<br />What if we consider a similar scenario for classes. All classes in Java extend the Object class by default. Also we know that Java does not support multiple (implementation) inheritance. <br />So if ClassB extends ClassA, does ClassB also extend the Object class directly? Or does it extend the Object class only through ClassA?<br /><br />If the later was mskumarnoreply@blogger.comtag:blogger.com,1999:blog-7955003209126272036.post-17375717519524060652010-02-16T19:04:35.561+05:302010-02-16T19:04:35.561+05:30what you are trying to compile is different from w...what you are trying to compile is different from what's stated in the quoted lines... the quoted lines mean that a method which is declared 'final' in the Object class will cause a compile time error if an interface will try to have a method with the same signature... hope this helps!Geekhttps://www.blogger.com/profile/00648920090539126396noreply@blogger.comtag:blogger.com,1999:blog-7955003209126272036.post-89396907164885312462010-02-01T17:33:31.883+05:302010-02-01T17:33:31.883+05:30:) Very nice article and discussion.
But below quo...:) Very nice article and discussion.<br />But below quoted text is still not clear to me :<br /><br /><b>Remember if the interface tries to declare a public instance method declared 'final' in the Object class then it'll result into a compile-time error. For example, 'public final Class getClass()' is a public instance method declared 'final' in the Object class and ritsnoreply@blogger.comtag:blogger.com,1999:blog-7955003209126272036.post-26380228548345520622008-06-28T18:31:00.000+05:302008-06-28T18:31:00.000+05:30S. Gregory: Thanks for your active participation. ...<B>S. Gregory: </B>Thanks for your active participation. I believe the discussion will help all of us to refine our concepts. Please find below my take on the various pieces of your last comment (<I>pieces italicized</I>) and let me know in case you differ anywhere.<BR/><BR/><I>Runnable r = ...;</I><BR/><BR/>'<B>r</B>' is not an <B>object</B>... it's only a <B>reference of type Runnable</B> whichGeekhttps://www.blogger.com/profile/00648920090539126396noreply@blogger.comtag:blogger.com,1999:blog-7955003209126272036.post-22873923734419015642008-06-28T01:58:00.000+05:302008-06-28T01:58:00.000+05:30What's more interesting to think about is this sit...What's more interesting to think about is this situation:<BR/><BR/>Runnable r = ...;<BR/><BR/>Object o = r;<BR/><BR/>Even if runnable implicitly has a definition of all of the methods of Object, that alone doesn't make r assignable to Object. Java doesn't support duck typing.<BR/><BR/>The key thing to think about though is that r is actually an object (or null but that's not interesting in this S. Gregoryhttps://www.blogger.com/profile/01536457732483717578noreply@blogger.comtag:blogger.com,1999:blog-7955003209126272036.post-63036780225641461032008-06-28T01:06:00.000+05:302008-06-28T01:06:00.000+05:30Don: Good point! The designers of Java might have...<B>Don: </B> Good point! The designers of Java might have thought of not having this approach probably because it'll add an <B>extra indirection</B> for accessing those Object class methods in all the classes in Java - irrespective of whether they implement any interface or not because in that case every class will automatically implement that super interface via Object class ... right? These Geekhttps://www.blogger.com/profile/00648920090539126396noreply@blogger.comtag:blogger.com,1999:blog-7955003209126272036.post-27368488896147388642008-06-26T23:30:00.000+05:302008-06-26T23:30:00.000+05:30I'm confused. Why would an interface need to exte...I'm confused. Why would an interface need to extend Object? I think there must be confusion about what is an object vs what is a type.<BR/><BR/>Let's take the Runnable interface.<BR/><BR/>public interface Runnable{<BR/><BR/> public void run();<BR/><BR/>}<BR/><BR/>We know we can't create an instance of it right? We can't go Runnable r = new Runnable();?<BR/><BR/>Of course we can go.<BR/><BR/>S. Gregoryhttps://www.blogger.com/profile/01536457732483717578noreply@blogger.comtag:blogger.com,1999:blog-7955003209126272036.post-3131574594187709112008-06-26T22:10:00.000+05:302008-06-26T22:10:00.000+05:30Why wasn't this made more explict by having an int...Why wasn't this made more explict by having an interface named Interface which defines the methods currently defined for Object.<BR/><BR/>Object implements Interface, and every interface implicitly extends Interface in much the same way as every class implicitly extends Object?<BR/><BR/>Problem solved, no?Unknownhttps://www.blogger.com/profile/11028034140600027205noreply@blogger.com