Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "interface" Watch "interface" New topic
Author

interface

ronak mehta
Greenhorn

Joined: Aug 14, 2001
Posts: 23
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

Joined: May 05, 2000
Posts: 13974
Yes.
You can even do this:

[This message has been edited by Thomas Paul (edited August 31, 2001).]


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Roopa Bagur
Ranch Hand

Joined: Nov 03, 2000
Posts: 267
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?

 
Consider Paul's rocket mass heater.
 
subject: interface
 
Similar Threads
final class
MasterExam OO question
interface&classes casting
interfaces used to work on my system but now they dont :)
Regarding Interface Concept