Inheriting built-in functions

Let’s say I have this code:

class A
{
    public void OnPointerEnter(PointerEventData eventData)
    {
        StartHover();
    }
    public void OnSelect(BaseEventData eventData)
    {
        StartHover();
    }
    public void OnPointerExit(PointerEventData eventData)
    {
        StopHover();
    }
    public void OnDeselect(BaseEventData eventData)
    {
        StopHover();
    }



    void StartHover()
    { 
        Debug.log("A");
    }

    void StopHover()
    {
        Debug.log("A");
    }
}

class B : A
{
    void StartHover()
    { 
        Debug.log("B");
    }

    void StopHover()
    {
        Debug.log("B");
    }
}

If I now make a script of class B attached to a button will the onPointerEnter functions still call the starthover in class B? Is this a good example of how to use inheritance? (I have multiple interface objects that should have some logic upon interaction, but some of it is common). Do I understand correctly that simply redefining the function I will get “BA” but using new keyword I’ll get only “B” because the old version is overriden?

You are correct. However, be sure to mark the functions in A as “public virtual void” and the functions in B as “public override void”; otherwise, the functions will only be shadowed, not overridden (this is rarely desirable).

not quite sure what you are looking for, but if you want to call both the base classes function and the new one you could do this.

public class A{
	public void foo(){
		Debug.Log("a");
	}
}
public class B:A{
	public new void foo(){
		Debug.Log("b");
		base.foo();
	}
}

this will make it so when you call b.foo(); the console will output ‘b’ on one line then ‘a’ on another. if you want ‘a’ before ‘b’, just call base.foo(); before the Debug.log();