• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface  RSS feed

 
mandeepsangwan kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

how object of interface is made here
though we know object of interface can not be made ......
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I edited your post to UseCodeTags to make your code more readable. Looks much better don't you think?

You have not created an instance of the interface. You have created an anonymous class that implements the interface. Have a read through the Java Tutorial on Anonymous Classes.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mandeepsangwan kumar wrote:how object of interface is made here
though we know object of interface can not be made ......

Well, that last statement is patently wrong, since you've just shown that it IS possible.

It's called an "anonymous class", and the fact is that it's a subclass of the interface; you just don't know what it's called, so you can't refer to it by name.

I suggest you read the tutorials on the subject.

HIH

Winston

[Edit] Aagh! Too late AGAIN .
 
mandeepsangwan kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you , i was just on the topic of inner classes .......
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're very welcome.

Did you write this little example yourself or have you copied it from somewhere? If you have copied it from somewhere then can you please QuoteYourSources. It's a copyright thing so if you could do that it would be most appreciated. Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!