can you create interface instance ?
Answers were Sorted based on User's Feedback
Answer / sanddep
what uday did here was not creating the instance of the interface but he implemeted the interface through the anonymous class.Now the instance created is of that anonymous class which has implemented the interface and its reference is stored in the variable t.
Regards
Sandeep
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / jenith michael raj
This is simply anonymous inner class, he implements the
interface in that class, that is why its working
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / shankar patil
You can't create an object without method implementations.
Anonymous inner classes allow you to do.
public interface MyInterface {
public void myMethod() ;
}
MyInterface myIntfObj = new MyInterface() {
public void myMethod() {
}
};
myIntfObj.myMethod();
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / anonymous
Hi Uday,
That's really nice however I think you have just created and anonymous class implementing the interface, and then invoking the wish method :)
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / ramu
hey uday u r wrong
In your program you are not created obj for interface, you have given anonymous implementation for 'Test' interface and instantiated that anonymous class only but not the interface.
for conformation call getClass() on 't'.(t.getClass())
| Is This Answer Correct ? | 1 Yes | 0 No |
it was just a bullshit you did man
you are creating jus he anonymmous class and is just treate
a subclass of the paricular inerface and also the override
mehod execute
learn java because prople like you just amajed those people
those don' know java
so try your self first thing that java is the whole thing
which realed to Object class not he object so learn it
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / manikandansit
hello Anil,
jus encourage who posts the answer but don;t do it over,why
because new one thinks that answer is correct instead of
wrong ok.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / neeraj
if we implements a class with an Interface then it will
compile time error i.e U must give the body of a method in
your class , so it is an anonymous class.We cannot create
Instance of an Interface.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / syed
My dear uday can u please create an instance of Abstract class but I think u cant create an instance of Abstract class
| Is This Answer Correct ? | 0 Yes | 0 No |
What is a newline character in java?
What is difference between final and immutable?
abstract class Demo { public void show() { System.out.println("Hello I am In show method of Abstract class"); } } class Sample extends Demo { public void show() { super.show(); System.out.println("Hello I am In Sample "); } } public class Test { public static void main(String[] args) { //I WANT TO CALL THE METHOD OF BASE CLASS IT IS POSSIBLE OR NOT CAN WE USE SCOPE RESOLUTION OPERATOR TO CALL OR JAVA NOT SUPPORTED THAT :: OPERATORE } }
What is the Vector class?
Is space a character in java?
What is the difference between abstraction and encapsulation?
What are Normalization Rules? Define Normalization?
Which sorting is best in java?
How to count occurrences of each duplicate element in a list {a,b,d,c,a,b} ? Thanks in Advance
What do you understand by the term wrapper classes?
how to transactions(Bank transactions) in business process in ejb?
class test { private static void main(String []adsf) { } } explain me that the above code is error or exception