• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not related to Exam

 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Arsineh Keshishian
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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 public.

Bye
Arsineh
[ June 04, 2008: Message edited by: Arsineh Keshishian ]
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • 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.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getDeclaredMethods() is what you want.
 
Sarath Koiloth Ramath
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic