This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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