on 03-15-2007 4:05 PM
In WDJ, if you want to use some method M of some subclass B that inherits from some class A (because you've customized method M in superclass B), don't you call the method of class B in your WDJ code ???
sorry - I meant that you've customized M in subclass B, not superclass B ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
static class A {
public void M() {
System.out.println("A.M");
}
}
static class B extends A {
public void M() {
System.out.println("B.M");
}
}
public static void main(String[] args)
{
A a = new B();
a.M();
}
will print "B.M". Now, what is your question again ?
Best regards, Maksim Rashchynski.
Hi Maksim - thanks for taking the time to reply.
I interpret your response to mean that you must reference the subclass B specifically if you want to use a method of the subclass B (not the corresponding method of its superclass) .
In your case above, you reference subclass B specifically because you request "a" as a new instance of "B".
Correct ?
Thanks again
djh
Yes, Maksim - I understand polymorphism.
I asked the question because I wanted to be sure that there was no "weird" way of getting the method of a subclass without specifically referring to the subclass, e.g. something like a generic "DEF-like" statement which says that in the program, any reference to superclass A should always be interpreted as reference to subclass B ...
Reason I asked is that I'm preparing a blog post on SAP Worfkflow delegation, SAP BAdI implementation, and SAP implementation of polymorphism in WDJ.
So I wanted to be sure of my facts about WDJ before I posted the blog ...
Thanks again
djh
David,
Actually, this is just Java.
As with any OOP language you get polymorphic objects behavior -- you may use subclass whenever superclass is necessary. Also the version of method called will be always method from the "most derived class" -- actual class used when instantiating object, not the version from class used for declaring variable.
By the way, this differs java from C++/C# -- all methods are virtual by nature, you should not use "override" keyword to explicitly mark method as overwritten. This C# feature bugs me several times when I did my first steps with .NET.
Valery Silaev
SaM Solutions
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.