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
Write a method to check if input string is palindrome?
What is the difference between abstract classes and interfaces?
Are arrays passed by reference in java?
What are the different types of multitasking?
What are examples of modifiers?
Difference between arraylist and hashset in java?
How to sort an array from smallest to largest java?
What are the default and parameterized constructors?
Can a class be private or protected in java?
What does the @override annotation do?
Can we define a package statement after the import statement in java?
What is the difference between serializable and externalizable interface?
Why should we use singleton pattern instead of static class?
What is the maximum size of arraylist in java?
How objects are stored in java?