can you create interface instance ?
Answer Posted / udaykiran
Why Not?
Yes, Even we can create an instance of interface and
abstract class also.
just see this below simple example
Main.java
-----------
interface Test
{
public void wish();
}
class Main
{
public static void main(String[] args)
{
Test t=new Test()
{
public void wish()
{
System.out.println("output: hello how r u");
}
};
t.wish();
}
}
cmd> javac Main.java
cmd> java Main
output: hello how r u
in above case Test is an interface but i created the object
for that interface.
| Is This Answer Correct ? | 54 Yes | 92 No |
Post New Answer View All Answers
What are the important features of Java 9 release?
What is basic syntax?
How does singleton class work?
What are different types of encoding?
Can we catch more than one exception in single catch block?
What are functions in java?
What is subsequence of a string?
Can you write a java class that could be used both as an applet as well as an application?
How to sort list of list in java?
How will you compute size of a structure?
what is interface in java? Explain
What is a dynamic array in java?
How do I print a “?
How does arraylist work in java?
Can a class have multiple superclasses?