Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface

 
ronak mehta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can interface is intantiated?
if no
then
interface Inter{}
class A implements Inter
class B extends A
{
A a=new B();
Inter i=a;
}
is legal?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
You can even do this:

[This message has been edited by Thomas Paul (edited August 31, 2001).]
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your example you are using the Interface as a variable type that is all. Java lets you use Interface name as variable type as long as the variable is referencing a class that implements that interface.
Originally posted by ronak mehta:
can interface is intantiated?
if no
then
interface Inter{}
class A implements Inter
class B extends A
{
A a=new B();
Inter i=a;
}
is legal?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic