John007
New member
- Joined
- Jan 19, 2021
- Messages
- 2
- Programming Experience
- 5-10
Hi
I have two classes ClassA and ClassB. ClassB is inherited from ClassA. I want the Sub1 in ClassA to handle some situations but for others I want to leave it for Sub2 in ClassB to handle. I am not sure how to set this up. My skeleton code is below but its obviously not correct. Any help would be appreciated.
Thanks
Regards
I have two classes ClassA and ClassB. ClassB is inherited from ClassA. I want the Sub1 in ClassA to handle some situations but for others I want to leave it for Sub2 in ClassB to handle. I am not sure how to set this up. My skeleton code is below but its obviously not correct. Any help would be appreciated.
Thanks
Regards
C#:
public class ClassA
{
public string xyz = "abc";
void Sub0()
{
Sub1(xyz);
}
public void Sub1(string xyz)
{
if (true)
{
//Handle it here if condition is true else leave it for Sub2 in ClassB to handle
}
else
{
//Let it handled in Sub2 in ClassB
Sub2(xyz);
}
}
public abstract void Sub2(string xyz);
// I am getting this on above line; 'ClassA.Sub2(string)' is abstract but it is contained in non-abstract type 'ClassA'
// How can I fix it? I don't want to make ClassA abstract
}
class ClassB : ClassA
{
public override void Sub2(string xyz)
{
// Handle it here
}
}
Last edited: