jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes About interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About interface " Watch "About interface " New topic

About interface

Pratik Thakare

Joined: Aug 29, 2012
Posts: 3
Hi I am just a beginner for java
I have 1 doubt
Q) I read that we can create a object of an interface . This is True but interface do not have constructors. So can any body please explane me What will be the flow . i mean how does this object is created ?
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11815

You can create an object/instance of a class that IMPLEMENTS the interface...so assuming the class Widget implements WorkerBee, you can do this:

WorkerBee myBee = new Widget();

so the object is really a Widget, but you can treat it like a WorkerBee.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6264

Maybe you're thinking about an anonymous class:

Junilu - [How to Ask Questions] [How to Answer Questions]
Pratik Thakare

Joined: Aug 29, 2012
Posts: 3
Thanks a Lot ....
It is sorta covered in the JavaRanch Style Guide.
subject: About interface
jQuery in Action, 3rd edition