• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help in interfaces needed.  RSS feed

 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check whether my impression is right or wrong.

An interface can extend any number of classes.

An interface can extend any number of interfaces.

If answer to above questions is no how is multiple inheritence achieved.
 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know thisabout interfaces
They are 100% abstract and public.
They can never be marked protected(members or methods).
They have to be implemented by a class.
a class can belong to any inheritence tree and yet it can implement an interface.

please accredite any point I might have failed to cover
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface cannot extend any classes, but can, as you say, extend several other interfaces. You can use several interfaces to mimic multiple inheritance.
And you are right about public, but that is the methods in an interface, not the interface itself.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interface by definition is NOT a class. So how can a non-class things can extend class? Only classes can extend classes and interfaces can extend Interfaces.

Hope this helps.
 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so can a interface be used as a polymorpic argument of a method of a class?
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varun Goenka wrote:so can a interface be used as a polymorpic argument of a method of a class?
Yes.

Go and have a look at the java.util.ArrayDeque class, which implements the java.util.Deque and java.util.Queue interfaces. You can declare a reference

Queue myArrayDeque;

or

Deque myArrayDeque;

and pass an ArrayDeque object to each reference. [You can also use ArrayDeque as a stack implementation]
 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it can!


 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey ....no one said interfaces could be REFERENCED in here!
How am I supposed to know that in case I know nothing about interfaces.
Please let everyone know everything about interfaces in a thread that deals with basic knowledge about interfaces.
Now what more is there for me to know.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!