java inheritance

hello,

i'm trying to use a super class called A and a derived class called B.

class A has a method that gets a parameter of type C which is also a super class. class D inherites class C. The code:

class A{

public void foo(C c){...}

}

Class B{

public void foo(D d){...}

}

it gives me a compilation error, how can i make this work?

thanks!!

[406 byte] By [shdavida] at [2007-11-27 11:24:15]
# 1

Lowercase 'c' in class.... What error do you get?

CeciNEstPasUnProgrammeura at 2007-7-29 15:57:11 > top of Java-index,Java Essentials,Java Programming...
# 2

this was just a typo...

i'm getting:

The method foo(D) in the type B is not applicable for the arguments (C)

thanks

shdavida at 2007-7-29 15:57:11 > top of Java-index,Java Essentials,Java Programming...
# 3

So somewhere you're *calling* that method with a C as a parameter. And your B does not extend A so it doesn't inherit the other method.

CeciNEstPasUnProgrammeura at 2007-7-29 15:57:11 > top of Java-index,Java Essentials,Java Programming...
# 4

ok, i made some errors in my first questions, sorry for that:

class A{

public void foo(C c){...}

}

class B extends A{

public void foo(D d){...}

}

and as i said D extends C and the error:

The method foo(D) in the type B is not applicable for the arguments (C)

is a compilation error.

thanks again!!

shdavida at 2007-7-29 15:57:11 > top of Java-index,Java Essentials,Java Programming...
# 5

Iam not sure But I believe You cant redefine a methods signature as you did.

Of course method redefinition is always acceptable.

charllescubaa at 2007-7-29 15:57:11 > top of Java-index,Java Essentials,Java Programming...
# 6

> The method foo(D) in the type B is not applicable for

> the arguments (C) is a compilation error.

The code you posted compiles just fine. The problem is elsewhere. Time for you to post an SSCCE* that actually demonstrates the compiler error.

*http://mindprod.com/jgloss/sscce.html

> i'm trying to use a super class called A and a derived class called B.

Hopefully, you're using more meaningful names than that. And if you are, you should use those names in the sample code you post here (or at least *something* meaningful).

~

yawmarka at 2007-7-29 15:57:11 > top of Java-index,Java Essentials,Java Programming...