File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Not related to Exam 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 » Java » Beginning Java
Bookmark "Not related to Exam" Watch "Not related to Exam" New topic
Author

Not related to Exam

Sarath Koiloth Ramath
Ranch Hand

Joined: May 07, 2008
Posts: 52
Hi i try to print all the methods in a class which extends another class.But i can print all the methods excluding the super class.I am getting the Object class methods but not the methods in the super class.


J 4 Java
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

If this is a question that's not related to the SCJP exam, then why are you posting it in the SCJP forum?

I'm moving it to the Java in General (Beginner) forum for you. Please carefully choose a forum and use a meaningful subject line when you ask a question.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Arsineh Keshishian
Greenhorn

Joined: Apr 21, 2008
Posts: 19
Sarath,

with Method[] mm=s.getClass().getMethods();
you only get the methods in Class S and R which have the access modifier public, not protected and not private.
Since getMethods() is a method in Class Class, in package java.lang, it won't find the private and protected mehtods neither in Class S nor in Class R.
So you have to modify the methods you want to be found in both classes R and S to public.

Bye
Arsineh
[ June 04, 2008: Message edited by: Arsineh Keshishian ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Jesper, you're not calling reflection a beginner's topic, surely? I'll resist the temptation to move it again, however.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
getDeclaredMethods() is what you want.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Sarath Koiloth Ramath
Ranch Hand

Joined: May 07, 2008
Posts: 52
Thanks for all the reply

Is there any method to print down the printS1S2(): ie the inherited method.
And please tell how to show the private and protected methods in a class.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Originally posted by Peter Chase:
getDeclaredMethods() is what you want.

For the methods in this class. Use getSuperclass() to get a reference to the super class.

In a recursive way:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not related to Exam
 
Similar Threads
Dan's Mock
overriding
hiding private method in subclass
Question on Overriding
Inheritance Confusion