function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SIVASASNKARSIVASASNKAR 

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 "

SamuelDeRyckeSamuelDeRycke

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.

 

Anup

BryanHartBryanHart

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();
myClass.someMethod();

 

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.