aspose file tools*
The moose likes Beginning Java and the fly likes Interface(URGENT) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interface(URGENT)" Watch "Interface(URGENT)" New topic
Author

Interface(URGENT)

Angela D'souza
Ranch Hand

Joined: Jan 16, 2002
Posts: 469
Hi,
Let's say I have Interface class A and I have another class B which Implements Class A.
(1)So can I say Interface class are always superclass of class(which implements interface)?
(2)Then what is difference between extends and implements?
Thanks,
Angela
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
interfaces and classes are two different things...there is no such thing as an "interface class."
A class you define can extend ONE class, and/or implement one or more interfaces.
An interface you define can extend one or more interfaces. It obviously can't implement any interfaces, because interfaces are abstract and contain no implementation.


Rob
SCJP 1.4
Angela D'souza
Ranch Hand

Joined: Jan 16, 2002
Posts: 469
Okey Let's say I have two classes & one interface:
Interface A
class B
class C
class D
Now class B implements A
{
}
class C
{
B b;
class D = new class(b);
}
class D
{
in constructor D(interface A);
}
Can I do this? Technically why? Is this because Class B subclass of Interface A???
HTH,
Thenks,
Angela
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
You can try writing up your question in real java code and compiling it, and seeing what the compiler does.
Also, class B is not a subclass of anything. Class B implements the interface A. ONLY interfaces can extend other interfaces, and then you don't say one interface is a "subclass" of another, you say it's a "subinterface". Keep these two concepts separate.
[ April 25, 2002: Message edited by: Rob Ross ]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You can do it because B is an A.
Let's put names to these things.
Let's make class B an Apple and interface A, things with seeds:

interface ThingsWithSeeds {}
class Apple implements ThingsWithSeeds {}
class Garden {
___void plantSeeds(ThingsWithSeeds s) {}
}
class Test {
___public static void main(String[] args) {
______Apple apple = new Apple();
______Garden garden = new Garden();
______garden.plantSeeds(apple);
___}
This works because Apple is a ThingWithSeeds.
note that the underscores are used only to help with spacing. The code tag makes the code too small to read.
Notice that you could also code it this way:
class Test {
___public static void main(String[] args) {
______ThingsWithSeeds seeds = new Apple();
______Garden garden = new Garden();
______garden.plantSeeds(seeds);
___}
[ April 26, 2002: Message edited by: Thomas Paul ]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Angela D'souza
Ranch Hand

Joined: Jan 16, 2002
Posts: 469
Originally posted by Rob Ross:
You can try writing up your question in real java code and compiling it, and seeing what the compiler does.


I compiled works fine. But one question I have is then what is difference between Subinterface and child or subclass?
Thanks
Angela
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Angela, a sub-interface extends another interface, while a subclass extends another class.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interface(URGENT)