File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Not related to Exam" Watch "Not related to Exam" New topic

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: 15081

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 8 API documentation
Arsineh Keshishian

Joined: Apr 21, 2008
Posts: 19

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.

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

Joined: Oct 13, 2005
Posts: 46349
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

Joined: Oct 27, 2005
Posts: 20271

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:

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Not related to Exam
It's not a secret anymore!