method invocation of object through interface
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Sunday, June 24, 2001 05:50 AM

I am new programmer to java, as I learnt that interface do not extends any class including Object , but then how is possible to call the method of an Object from an inteface like public interface Abc { public void aMethod(); } class A implements Abc { public void aMethod() {} public static void main() { Abc abc = new A(); System.out.println(abc.toString()) ; } } now i have referred object A by interface Abc , and i call amethod which is not defined in interface so it shoul   More>>

I am new programmer to java, as I learnt that interface do not extends any class including Object , but then how is possible to call the method of an Object from an inteface like


public interface Abc


{
public void aMethod();


}



class A implements Abc


{


public void aMethod()


{}


public static void main()

{
Abc abc = new A();


System.out.println(abc.toString()) ;

}
}


now i have referred object A by interface Abc , and i call amethod which is not defined in interface so it should at least give an run time error
but it compile as well as work(run) fine

   <<Less

Re: method invocation of object through interface

Posted By:   Luke_Reeves  
Posted On:   Sunday, June 24, 2001 12:56 PM

The toString member function that you're calling is actually inherited from the base Object class. Even though a class can implement an interface, it is still a normal object like everything else.
About | Sitemap | Contact