+ Start a Discussion

How to write a "Test class" for "Inheritance Class"

I have a parent and child classes...i.e.,,,first and second classes..


in second class extends first class..


In the test class i create the object on second class in that i got the error like this " Error: Compile Error: Method does not exist or incorrect signature: [secondcls].add() at line 8 column 5 "


Could you post your classes and test code ?

Anup JadhavAnup Jadhav

It's probably because the method that you are trying to rference is private in the parent (or child class). Try changing the visibility (if possible) to public.




I believe that there is a different compile error for incorrect visibility. it says something like "the method _____ is not visible"


Do you have something like the following?

ParentClass myClass = new ChildClass();


If so, you have to declare myClass as a ChildClass.

this is because when you call someMethod, the compiler doesn't know that it is a ChildClass, it only knows that it was declared as a ParentClass which doesn't have the method.


If that isn't what you did, then I'm not sure... I'd have to see the code.