How to find Class's parent Classes
Hi guys
Does anybody know how can I find the Class's parent Classes. Thanks in advance.
Regards,
Mark.
Hey Mark,
From the child class, call getClass().getSuperClass() This will return the Class object of the parent of this class.
-- Bud
Similar Messages
-
How to listen to user actions in child class from parent class?
Hi,
I have a basic custom class ChildCustomForm that include a JTextField. In order to know what user types, I add a listener to
this textbox:
textField.addKeyListener( new KeyAdapter()
@Override
public void keyPressed( final KeyEvent e )
//user typed something
userTyped = true;
});Now I have another parent class that uses ChildCustomForm, and parent class has to know once user types, then set
its own userTyped flag.
My problem is: since I added listener in child class, I cannot get textfield and add listener again in parent class, so parent class will not be able to know as soon as user types (polling is not a good solution here).
I am wondering if there is a way to do this?
regards,jack_wns wrote:
I have a basic custom class ChildCustomForm that include a JTextField. In order to know what user types, I add a listener to
this textbox:You want to listen for input into the textbox, correct? This may take the form of keyboard input, or could be a paste-text event in which case your keylistener will miss it. I recommend that you look into a DocumentListener here so you will catch any changes, be they keyboard or cut or paste.
My problem is: since I added listener in child class, I cannot get textfield and add listener again in parent class, so parent class will not be able to know as soon as user types (polling is not a good solution here).The observer pattern may work here. -
How can I casting from parent class to children class
Dear,
Could someone help me to casting from parent class to children class.
I have class like this
class parent{
String name;
String id;
public String getId() {
return id;
public void setId(String id) {
this.id = id;
public String getName() {
return name;
public void setName(String name) {
this.name = name;
class children extends parent{
String address;
public String getAddress() {
return address;
public void setAddress(String address) {
this.address = address;
public children() {
public children(parent p) {
//Do init super class here
In the constructor
public children(parent p) {
//Do init super class here
I like to init super class by object p (this is instance of parent class). The way to do is using:
public children(parent p) {
super.setId(p.getId());
super.setName(p.getName());
But I don't like this, because, for example I have parent class with over 30 proberties, it take time to do like that.
There are any way to use super operation to init parent class, for example super = p;
Could you show me the way.
Thanks alotIf I understand your question correctly, you are in need of a copy constructor for you class Parent. A copy constructor behaves like this:
Parent one = new Parent();
one.setName("...");
//... and all other properties of interest
Parent two = new Parent(one);
//Now two != one, but one.getName().equals(two.getName) for property name and all othersThe copy constructor is programmed in the Parent class, more later. Then for your child class you can use it as follows
public class Children extends Parent {
public Children(Parent p) {
super(p);
}There are at least 3 ways of programming a copy constructor:
1. Just bite the bullet: type the assignment for each field this.name = p.getName()
2. Use reflection to find all common setters/getters dynamically and assign using them
3. Use a code generator that uses 2 to give you the code for solution 1 for you to paste in.
If you find doing this a lot, there are frameworks that can do these mappings, like Dozer
(PS be carefull with Date fields, don't copy the reference but create a new and equals instance, the dirty way would be this.birthdate = new Date(p.getBirthdate.getTime()); ) -
How to find out if a class is abstract?
Hi,
I'm loading some classes via ClassLoader. Some of them could be interfaces or abstract classes. I'm only interested in classes which I can instantiate. With myClass.isInterface() I can check if the class is an interface, but how can I find out if it is an abstract class? I'm missing the method Class.isAbstract().
FrankSystem.out.println( Modifier.isAbstract(Foo.class.getModifiers()) );
-
How to find out the batch class link of the batch record in the MSC3N
Hi,
I would like to know how to pull out the class type and the characteristic value for a batch which is found in MSC3N.
For example, the following is MSC3N screen showing material (INM000000001724945) and batch (A000001117) tie to batch class “XXXXXXXX”.
Hence, I would like to know:
How to pull out the class type and the characteristic value for a batch record which is found in MSC3N? What are the table? The table show in the F1 key is not a table.
There are two batch classes setup in the system “XXXXXXX” and “YYYYYYY”, my question is why system decides to use the batch class “XXXXXXX”? Where is the system setup to determine this?
Thanks
TuffHi
The table MCH1 keeps the information about Material, Batch and Internal object no.: Batch classification (CUOBJ_BM).
The field CUOBJ_BM in MCHA represent the 'Key of object to be classified' (AUSP-OBJEK). The first 18 characters of AUSP-OBJEK.
In CABN (Characteristic) the field ATINN and ATNAM is important. The link between CABN and AUSP is through ATINN. -
How to find sun/applet/AppletViewer class?
Hello, everyone,
I have successfully deployed Form Server Applications in several
ways as following:
1. Using Jinitiator 1.1.7.11 plug in to run Forms inside Web
browser in Windows 98 OS &IE4.0 SP1.
2. In Windows 98 OS DOS Command prompt line,using Appletviewer
to run remote NT
Server's Forms application with format: C:\>Appletview
http://appserver:9999/webhtml/example.html. The
form runs smoothly in a AppletViewer window.
3. In NT4.0 OS SP3, run form inside IE4.0 SP1 browser without
Jinitiator 1.1.7.11 plug in program, but I
must set CLASSPATH Env variable including
C:\ORANT\JDK\LIB\CLASSES.ZIP & C:\ORANT\FORMS60\JAVA, or else
the error message shows: class no found:sun/applet/appletviewer.
But I even encounter some problem:
1. In the above first way, jinit.exe(Jinitiator 1.1.7.11
version) can not run in my NT4.0 SP3 OS. So the
above first way of running Form can only succeed in my Windows98
OS. Has anybody installed jinit.exe
successfully in NT4.0 SP3?
2. In the above third way, I try to run Form inside my IE4.0 SP1
in Windows98 OS. I tried to set the
CLASSPATH correctly as above describled, but I failed. I always
got the above mentioned error message. I
don't know why in windows98 the appletviewer class can not be
found but in NT it can.
Anyone can help me out? Thanks in advance.
Robby
nullbut problem is:
the class name is a string "JFrame", which is
how to solve the problem?It is simply not possible.
If you have javax.swing.JFrame, you can use Class.forName(). But then you've already got the package.
Beyond that, if you've ever decompiled code, you'd have seen that import statements don't exist in bytecode and all class references are by their full names. There is no facility in java to get the list of loaded classes, or to search for a class this way -
How to find out the callers class?
Is it possible to find out whats the callers class from within a method without having the caller to pass a reference to itslef?
AkoThere are many posts on the subject. Two things.
1) Yes it's possible by getting a stacktrace.
2) No one should ever want to implement this. It perverts the idea of the language. -
How to find the main java class file
I need to write a Java program which MUST know one of these:
1) the full path to the main java class (the class with "main" method)
or
2) access to the main class as byte array.
If i know (1) then I have no problems reading the main class into byte array, but the main target is still (2).
Another option is if the main file is in JAR, which again leads to problems, because I cannot access the file in normal way, but I still need access to the exact byte stream.
Any help is highly appreciated! Thanks!
<<< Ivan Davidov >>>You could try somthing like this in your main-method:
InputStream is = getClass().getResourceAsStream(<"myModifiedPackageName/MyClass.class">);I don't know if this works though.
Have a look at the API doc for this method.
-Puce -
How can I know a parent class of a certain class? which FM can be used?
It seems SEO_CLASS_TYPEINFO_GET can not work.
Hi Anirban,
The function module always return a class_not_defined exception.
Is there anything wrong when loading this?
REPORT ztest123.
DATA : lv_class type CSMCLASS.
DATA : ls_super_class type CSM_CLINHL.
lv_class = 'Z_CL_DEMO_STUDENT_02'.
CALL FUNCTION 'SCSM_MD_CLASS_GET_SUPER_CLASS'
EXPORTING
NAMESPACE
SCHEME = SCHEME_BC
class = lv_class
importing
super_class = ls_super_class
NS_SUPER_CLASS =
exceptions
class_not_defined = 1
class_is_base_class = 2
OTHERS = 3
IF sy-subrc = 0.
ENDIF.
BREAK-POINT.
Best regards, -
Actual Mechanism of Object class as Parent Class to all the classes
Hi All,
We know that all the classes in the java platform are descendants of Object class. Even if we are writing a new class also, in the absence of any other explicit superclass, every class is implicitly a subclass of Object. As we are not extending the Object class directly, then how come the methods in the Object are inheriting to the Sub class what we have written? How the java maintain this heirarchy?
Can you please explain this elaborately?
Thanks in Advance,
UdayUdaya Shankara Gandhi wrote:
Hi All,
We know that all the classes in the java platform are descendants of Object class. Even if we are writing a new class also, in the absence of any other explicit superclass, every class is implicitly a subclass of Object. As we are not extending the Object class directly, then how come the methods in the Object are inheriting to the Sub class what we have written? How the java maintain this heirarchy? Because the language is defined that way. Compilers implement the language according to the rules of the JLS. Exactly how they do that is undefined. It's up to each compiler. As long as it follows the rules defined in the JLS for parsing the code and generating the .class file, that's all that matters. However, somewhere in the compiler is code that does approximately this:
if (class has an extends clause) {
generate corresponding bytes for extends in .class file
else {
generate bytes for extends java.lang.Object in .class file
}No great mystery, nor philosophical question. -
How to find one pipeline service's corresponding ABAP class ?
Hello guru,
I am in t-code: SXMB_ADM, then go to "Display Pipeline Definition", for example, I choose "SAP_CENTRAL" and try to investigate the pipeline steps in "SAP_CENTRAL" pipeline, and I find these pipeline steps:
Receiver Identification is for "Receiver Determination" step, and its' pipeline service" PLSRV_RECEIVER_DETERMINATION", but when I find this Class in SE24, I find nothing with name "PLSRV_RECEIVER_DETERMINATION".
Please tell me how to find the corresponding ABAP class of a pipeline service.
Thanks in advance.Chen,
Are u looking for this class -CL_XMS_PLSRV_IE_ADAPTER ? Go to SE80 choose class Interface give SRV and click the down arrow icon, it will give u some list of classes. I don't know if it's useful or not, just do a seach..
raj. -
Is there anyway I can find all the methods that are available to
in a class with the help of java code. For example: the Math class. Is there a
programming technique to find all the methods available in the
math class or any class.
Thanx
-RedsHi raja17 :
try this example and you'll understand how to find all method of class :
//this code print all the return type and the names of a class :
Class l_class = Class.forName("javax.swing.JFrame");
java.lang.reflect.Method[] l_method = l_class.getMethods();
for (int i =0; i< l_method.length ; i++) {
System.out.println(l_method.getReturnType() +" "+ l_method[i].getName()); -
Even i call this() paramerterised constuctor in my class, Is super class su
Even i call this() paramerterised constuctor in my class, Is super class super() parameter less constuctor invokes?
I have excuted the following program. And result will be as follows:
Grandparent() constructor
Parent 25 constructor
Parent() constructor
Child() constructor
The program is below:
class ConstructorChain {
public static void main(String[] args) {
Child c = new Child();
class Child extends Parent {
Child() {
System.out.println("Child() constructor");
class Parent extends Grandparent {
Parent() {
this(25);
System.out.println("Parent() constructor");
Parent(int x) {
System.out.println("Parent(" + x + ") constructor");
class Grandparent {
Grandparent() {
System.out.println("Grandparent() constructor");
for this my excepected answer is
Parent 25 constructor
Parent() constructor
Child() constructor
because in parent class i defined this() constructor so, as my undersatnd is it never call Grand Parent Constructor as it is default parameterless constructor.
please Advise me
ArunaYou can't initialize a class without it's super classes constructor being run. So even if you call another constructor (of the same class), the parent classes constructor will still be called.
-
Want to find out parent class of a class without using getSuperClass
hi,
I am trying to write a code to find out the base class /interfaces of a class by its object and i dont want to use getSuperClass,getInterfaces methods.
Below is a snippet i tried but it does not work:
public class Test extends Parent{
public void disp(){
System.out.println(super.getClass().getName());
public static void main(String args[]){
Test test = new Test();
test.disp2();
this outputs the child class only does not output the parent class.
Is there any method to do so?
Thanks,
AnirudhOk, If it can not be done then i must not ask.
So you have answered it that it is not possible without these.Thats what i wanted to know.
Should have framed the question like is it possible?and if possible how?
Thanks
Anirudh -
How to get the class name static method which exists in the parent class
Hi,
How to know the name of the class or reference to instance of the class with in the main/static method
in the below example
class AbstA
public static void main(String[] args)
System.out.println(getXXClass().getName());
public class A extends AbstA
public class B extends AbstA
on compile all the class and run of
java A
should print A as the name
java B
should print B as the name
Are there any suggestions to know the class name in the static method, which is in the parent class.
Regards,
Raja Nagendra KumarWell, there's a hack you can use, but if you think you need it,Could you let me the hack solution for this..
you probably have a design flaw and/or a misunderstanding about how to use Java.)May be, but my needs seems to be very genuine..of not repeat the main method contents in every inherited class..
The need we have is this
I have the test cases inheriting from common base class.
When the main method of the test class is run, it is supposed to find all other test cases, which belong to same package and subpackages and create a entire suite and run the entire suite.
In the above need of the logic we wrote in the main method could handle any class provided it knows what is the child class from which this main is called.
I applicate your inputs on a better way to design without replicating the code..
In my view getClass() should have been static as the instance it returns is one for all its instances of that class.
I know there are complications the way compiler handles static vars and methods.. May be there is a need for OO principals to advance..
Regards,
Raja Nagendra Kumar
Edited by: rajanag on Jul 26, 2009 6:03 PM
Maybe you are looking for
-
I am using windows 8.1 my itunes close down if i try and go into the itunes store. my icloud works for about 5 minnutes then stops. i have deleated itunes and cloud and reloaded both and they still fail.
-
X200 auto-update BIOS upgrade failed? system no longer boots
Hi, I've had an X200 for around 7 months now and just did an auto-update earlier today. One of the items was a BIOS update, so I thought what the heck, it should be fine, always has been before. The update completed correctly and shuw down for reboot
-
Using Time Machine to backup a shared directory on Windows XP.
I have a shared directory on a Windows XP machine on my LAN that I would like to backup using Time Machine. Apparently Time Machine will not automatically backup shared directories so I created a soft link to the mount point, /Volumes/WindowsXP, and
-
DVD Player just displays static
Well, it's kind of hard to explain, but here is a screenshot of what DVD Player can look like when I try to play a movie: http://showmac.com/dvdstatic.jpg It seems to display random bits and parts from other on-screen gui elements. Like windows and m
-
IPhone 4S Preorder for October 28th
Is the US the only one that gets a preorder for the iPhone 4S? I'm wondering when the preorder date is for Singapore. Thanks!