cancel
Showing results for 
Search instead for 
Did you mean: 

Dumb question about super/sub classes in WDJ

Former Member
0 Kudos

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 ???

Accepted Solutions (1)

Accepted Solutions (1)

former_member181923
Active Participant
0 Kudos

sorry - I meant that you've customized M in subclass B, not superclass B ...

former_member182372
Active Contributor
0 Kudos

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.

former_member181923
Active Participant
0 Kudos

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

former_member182372
Active Contributor
0 Kudos

David, it is example of <a href="http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming">Polymorphism</a>. You can declare instance as superclass (A), instanctiate as subclass (B) and by referencing superclass variable (a of type A) access subclass functionality(method M).

former_member181923
Active Participant
0 Kudos

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

Former Member
0 Kudos

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

http://www.sam-solutions.net

former_member181923
Active Participant
0 Kudos

VS -

Thanks very much again ...

djh

Answers (0)