• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Not related to Exam

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 coderanch.

Bye
Arsineh
[ June 04, 2008: Message edited by: Arsineh Keshishian ]
 
Marshal
Posts: 80639
472
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesper, you're not calling reflection a beginner's topic, surely? I'll resist the temptation to move it again, however.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getDeclaredMethods() is what you want.
 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:
reply
    Bookmark Topic Watch Topic
  • New Topic