aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in certpal mock exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in certpal mock exam question" Watch "doubt in certpal mock exam question" New topic
Author

doubt in certpal mock exam question

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Please consider the following question from certpal mock exam simulator.




why doesn't the call floral.wait(1) gives compiler error. floral is of interface type Floral and it does not has wait method , then how can we invoke wait on floral reference.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

http://www.coderanch.com/t/568769/java/java/Marker-interface
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

Because wait() is defined in Object. And the compiler is smart enough to realise that any object that ends up implementing Floral (or any other interface) is still an Object, and so it will always be safe to call any methods that are defined in Object. Similarly, try toString(), equals() etc.
raju salla
Greenhorn

Joined: Jan 05, 2012
Posts: 18
hello,
Actually the wait() method is in Object class. We can call Object class's methods in any class in java. That's why it is not giving any error or throwing any exception. We can call Object class's method on any object in java. So there is no problem in calling wait() method on interface's floral object.

Thank you....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in certpal mock exam question