Can a reference variable of an interfece holds the address of an object of a class that implements that interfaceExampleclass X implements Y{ //Method Implementations of Interface public static void main(String args[]) { Y y=new X(); }}

Questions by questioninterest

Showing Answers 1 - 4 of 4 Answers

Pardhas

  • Aug 13th, 2006
 

Yes. reference variable of an interfece holds the address of an object of a class that implements that interface

  Was this answer useful?  Yes

Radhakrishna

  • Nov 9th, 2006
 

yes reference variable of interface type can hold the address of the object of a class which implements  that interface but we can call the only those methods which are declared in that interface and implemented in that class we can't call the methods which are defined in that class and which are not declared in that interface.

The belove example will help u in a better way

interface I{

void meth1();

}

class A implements I {

public void meth1(){

System.out.println("method declared in the interface");

}

public void meth2(){

System.out.println("method not declared in the interface");

}

}

public class test{

public static void main(String[] args){

I obj=new A();

obj.meth1();//legal

obj.meth2();//illegal

}

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions