Re: How to get the runtime class?
- From: Patricia Shanahan <patricia_shanahan@xxxxxxxxxxxxx>
- Date: Fri, 29 Apr 2005 23:32:55 GMT
Robert wrote:
I think it'll work in any method that the child would call inside the parent. Just probably not the ctor. Try any other method define the method in the abstract class and have the derived class call it but don't define it in the derived class. I bet it works.
Why would the constructor be any different?
public abstract class ClassTest {
String myClassName1 = getClass().getName();
String myClassName2;
ClassTest(){
myClassName2 = getClass().getName();
}
public static void main(String[] args) {
ClassTest t = new foo2();
System.out.println(t.getClassName());
System.out.println(t.myClassName1);
System.out.println(t.myClassName2);
}
String getClassName(){
return getClass().getName();
}
}class foo2 extends ClassTest{
}
prints:
foo2 foo2 foo2
.
- References:
- How to get the runtime class?
- From: Fredy
- Re: How to get the runtime class?
- From: Robert
- How to get the runtime class?
- Prev by Date: Re: Create InetAddress from a String.
- Next by Date: Re: Java Newbie... Read file at HTTP
- Previous by thread: Re: How to get the runtime class?
- Next by thread: Re: How to get the runtime class?
- Index(es):