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


Please Help Members By Posting Answers For Below Questions

what are Hostile Applets?

1598


What is an exception? difference between Checked and Unchecked exception in Java

550


What is array size in java?

490


What is the use of static class?

537


What is e java?

552






What is __ init __ functions?

537


What is numel matlab?

644


Differentiate between class and structure.

622


what is meant by encapsulation?

621


How do you override a method?

542


Does apple use java?

489


What was java originally called?

503


What is the collections api?

566


Which is easier .net or java?

638


Write an algorithm program in java for the following question.. In a VLSI design techniques,they used rectangles to design circuits. EVery rectangle is to be placed according to x,y coordinates. Check whether or not two rectangles overlap each other. Here overlapping of rectangles is acceptable, if 1) one rectangle intersect with other. 2) one rectangle fully covers other. The time of algorithm should not exceed o(n logn).

2227