Can we instantiate Interfaces?

Answers were Sorted based on User's Feedback



Can we instantiate Interfaces?..

Answer / paletipatisrinu

No we can instantiate interface directly.but we can create
instantiate of interface in directly

interface i1
{
public void wish();
}
public class A implements i1
{
public static void main(string...arg)
{
i1 o1=new A();
o1.wish();
}
public void wish()
{
System.out.println("we can create instantiate in directly");
}
}

Is This Answer Correct ?    17 Yes 1 No

Can we instantiate Interfaces?..

Answer / divya

You can only create a reference of an interface but cannot
instantiate.

Is This Answer Correct ?    10 Yes 2 No

Can we instantiate Interfaces?..

Answer / guest

no we can not.

Is This Answer Correct ?    6 Yes 4 No

Can we instantiate Interfaces?..

Answer / bharat vandar

No we can instantiate interface directly.but we can create
instantiate of interface in directly,only class can create
an object of interface


interface x
{
public void abc();
}
class ac implements x
{
x at = new ac();

public void abc()
{
System.out.println("Bharat");
}
}

Is This Answer Correct ?    3 Yes 1 No

Can we instantiate Interfaces?..

Answer / dhawal

answer no 1. is correct programatically but actually
instantiates means obtain the behavier of object we can do
this only by creating object of class ,object has state and
behaviour, in answer 1,we transfer state first and then
write behaviour in the class,then instantiate that class ie
like dynamic method dispatch.means therotically we can not
instantiate Interfaces

Is This Answer Correct ?    2 Yes 1 No

Can we instantiate Interfaces?..

Answer / anil pusuluri

One can't instantiate an interface. One can get a reference
to an interface.

Let's say Class A implements interface iA then we can't
instantiate IA
like IA a = new IA() -- this gives compilation error.

but we can get the referance to interface as below

IA a = new A()

Is This Answer Correct ?    1 Yes 0 No

Can we instantiate Interfaces?..

Answer / nagendra prasadu gandla

Yes you can instanciate but you have to implement the
methods of interface at the time of instanciation itself.

EX:
interface X
{
void abc();
}
class a
{
X z=new X(){void abc(){return;}};
}

Is This Answer Correct ?    5 Yes 7 No

Post New Answer

More Core Java Interview Questions

Why is the type for real numbers called double?

0 Answers  


What are parsers? Dom vs sax parser.

0 Answers  


How many bits are used to represent unicodde,ASCII,UTF-16 and UTF-8 characters?

2 Answers  


Can we have any code between try and catch blocks?

0 Answers  


can we access the super class method using subclass object?

4 Answers  






What is JVM ?

4 Answers   Phantom Technologies, TCS,


why we need this (1.object,2.class,3.data hiding,4.encapsulation,5.abstraction,6. polymorphism,7.inheritance)

2 Answers  


briefley expalin about the packages

3 Answers  


What are desktop procedures?

0 Answers  


What are parameters in a method?

0 Answers  


What is parameters example?

0 Answers  


What will happen inside init() in servlet. my interviewer asked servlet lifecycle. i said "once servlet is loaded in to memory init() will be called which performs servlet initialization " . Again interview asked what values will be initialized . what is difference between init() and init(ServletConfig config).

2 Answers   Infinite Computer Solutions, TCS,


Categories