• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in certpal mock exam question

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic