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 / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

What to expect from aClass.getSuperClass()

Thread view: 
F Da Costa - 16 Apr 2004 21:10 GMT
Hi all,

This question concerns the use of the Class.getSuperClass() method.

Situation:
abstract class Parent
abstract class Child extends from Parent
class GrandChild extends Child

Using GrandChild.getSuperClass() gives me the Parent class.
If this is intended i am surprised but fair enough.

The question is: how do i a hold of the Child class in a similar
fashion? I.e. how can i tell from which class the GrandChild extends
directly (so only 1 level up the tree rather than n levels).

I hope i described the issue correctly ;-)

TIA
Fermin DCG
VisionSet - 16 Apr 2004 22:37 GMT
> Hi all,
>
[quoted text clipped - 7 lines]
> Using GrandChild.getSuperClass() gives me the Parent class.
> If this is intended i am surprised but fair enough.

No, it gets the direct ascendent, 'Child' should be returned.

--
Mike W
Bryce (Work) - 16 Apr 2004 23:18 GMT
>Hi all,
>
[quoted text clipped - 7 lines]
>Using GrandChild.getSuperClass() gives me the Parent class.
>If this is intended i am surprised but fair enough.

You must have specified it wrong. I just tried the following:

Parent.java:
public abstract class Parent {

}

Child.java:
public abstract class Child extends Parent{

}

GrandChild.java:
public class GrandChild extends Child{
  public static void main(String [] args) {
     System.out.println(GrandChild.class.getSuperclass().getName());
  }
}

Running GrandChild give me:

Child

Using: j2sdk1.4.2_03

--
now with more cowbell
Roedy Green - 18 Apr 2004 00:24 GMT
>Using GrandChild.getSuperClass() gives me the Parent class.

That is surprising. Could you post your complete code, or convert your
code to a tiny app that demonstrates this strange behaviour.

Maybe you accidentally in your cut/paste wrote:

    GrandChild extends Parent

instead of

    GrandChild extends Child

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


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.