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 is set in java?
What is are packages?
What are the two types of java?
How do you create a bulleted list?
What is object cloning in Java?
Is string pool garbage collected?
What does the string method compareto () do?
What is ternary operator?
what is the use of pojo (plain old java objects)? how it is interact with crystal reports? pls urgent
What is the use of default method in interface in java?
Explain how hashmap works?
How to find the given number is a prime number or not by getting input from the user
Can we override the overloaded method?
What are constants?
What java is used for?