• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Object Class' methods in Interface

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when we create any interface, Object class' methods automatically loaded. I want to know Object class' methods are abstract methods or fully implemented? As examples:-

interface A
{}
class B
{
public static void main(String... ar)
{
A aa=null;
aa.wait(); //wait is the method of Object class
}
}

I want to know here wait() method is abstract or fully implemented and how it is calling by reference of interface A. We know that in interface every method is abstract. But when we call wait() method by reference, its working. Pleas advice me why???
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch. Please UseCodeTags when you post source code.

Class Object is a non-abstract class, so ofcourse all the methods in class Object are implemented. Your code example will not work, you'll get a NullPointerException because you're trying to call a method on a variable that's null.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mohd shahid wrote:We know that in interface every method is abstract. But when we call wait() method by reference, its working. Pleas advice me why



Any interface that doesn't have a super interface implicitly declares methods that match all the public methods of the Object class (See the Java Language Specification section 9.2). You can call the wait() method on an A reference because the object it is actually pointing at will be a concrete class that extended (either directly or indirectly) the Object class.
reply
    Bookmark Topic Watch Topic
  • New Topic