can we create instance for interface in java?

Answers were Sorted based on User's Feedback



can we create instance for interface in java?..

Answer / jyotisubhra ghosh

You can not instantiate an interface,however, u can create
its reference variabe.

You can just assign an object of a class (implementing the
interface) to the reference variable of the interface.

Is This Answer Correct ?    50 Yes 1 No

can we create instance for interface in java?..

Answer / guru

interface call2
{


void get1();
int a=8;
}


interface call extends call2
{


void get();

}



class interex implements call,call2
{

public void get()
{

System.out.println("hi");

}
public void get1()
{System.out.println("hsfwsi");}
}


class interex1
{
public static void main(String s[])
{
call e=new interex1();



e.get();
e.get1();

System.out.println(e.a);
}
}

second pgm
-----------
interface call2
{


void get1();
int a=8;
}


interface call extends call2
{


void get();

}



class interex implements call,call2
{

public void get()
{

System.out.println("hi");

}
public void get1()
{System.out.println("hsfwsi");}
}


class interex1
{
public static void main(String s[])
{
call e=new interex();



e.get();
e.get1();

System.out.println(e.a);
}
}

Is This Answer Correct ?    14 Yes 7 No

can we create instance for interface in java?..

Answer / venkateswararao

No,we cant create an instance if an interface in java , but
we can create a reference of an interface and we can
assign the object of a class to that interface reference.

Is This Answer Correct ?    6 Yes 0 No

can we create instance for interface in java?..

Answer / rani

yes

Is This Answer Correct ?    1 Yes 10 No

Post New Answer

More Core Java Interview Questions

When you say String is immutable, what do you mean by that? Say I have String s = "Ness" s= s+"Technologies"; What will happen? If the value gets appended, then what is the meaning of immutable here?

5 Answers   Ness Technologies,


Explain serialization and deserialization in java?

0 Answers  


What for read() function?

3 Answers  


what are the purposes of native, transiant key words?

2 Answers  


How many bits is a char?

0 Answers  






What are the different types of constructor?

0 Answers  


Can we start a thread twice in java?

0 Answers  


What technique is carried out to find out if a particular string is empty?

0 Answers  


What does int [] mean in java?

0 Answers  


Will the jvm load the package twice at runtime?

0 Answers  


There can be a abstract class without abstract methods, but what is the need to declare a class abstract if it doesn't contain abstract methods?

5 Answers   HCL,


What does microservices mean?

0 Answers  


Categories