Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

extends and implemens

Thread view: 
josh - 19 Mar 2007 10:22 GMT
Hi If I have a class A that extends a superclass BB and implements
another CC then we  can
say that A "is a" BB and "is a" CC ????

so when we make

BB = A

CC = A

are both equals?
Thomas Fritsch - 19 Mar 2007 11:21 GMT
> Hi If I have a class A that extends a superclass BB and implements
> another CC then we  can
> say that A "is a" BB and "is a" CC ????
Yes.

> so when we make
>
> BB = A
>
> CC = A

Your syntax here is a bit sloppy because you treat class names like
variable names. You probably mean something like:
   A  a = new A();
   BB b = a;
   CC c = a;
Then it is all well and the compiler will compile it without error.

> are both equals?

Signature

Thomas

Eric Sosman - 19 Mar 2007 13:36 GMT
> Hi If I have a class A that extends a superclass BB and implements
> another CC then we  can
> say that A "is a" BB and "is a" CC ????

    Terminology: A class cannot "implement" another class;
it can only implement interfaces.  BB must be a class, but
CC must be an interface, not a class.

    Having said that, then yes: A "is a" BB and A "is a" CC.
An Integer "is a" Number and also "is a" Comparable.

> so when we make
>
[quoted text clipped - 3 lines]
>
> are both equals?

    Well, this isn't quite right.  A and BB are class names
and CC is an interface name, but you can only work with variables
that refer to instances of these things, not with the things
themselves.  You need to flesh it out a bit, like

    A my_A = new A();
    BB my_BB = my_A;
    CC my_CC = my_A;

... and all is well, and all three my_* variables refer to the
same instance of A.

Signature

Eric Sosman
esosman@acm-dot-org.invalid



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.