File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in certpal mock exam question" Watch "doubt in certpal mock exam question" New topic

doubt in certpal mock exam question

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924

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
Matthew Brown

Joined: Apr 06, 2010
Posts: 4541

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

Joined: Jan 05, 2012
Posts: 18
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:
subject: doubt in certpal mock exam question
It's not a secret anymore!