Assignment - Openzeppelin Reading

  1. When should you put the virtual keyword on a function?

When it can be overridden by an inheriting contract.

  1. When should you put the keyword override on a function?

On the function that overrides the base function.

  1. Why would a function have both virtual and override keywords on it?

When the function overrides the base function and can still be overridden again. Like the transfer function.

1 Like
  1. To allow that function to be overridden by another function in an inheriting contract.
  2. When overriding a base function.
  3. When that function overrides another function but may itself be overridden.
1 Like
  1. A function that allows an inheriting contract to override its behavior will be marked at
    virtual
  2. The function that overrides that base function should be marked as override
  3. A function contains both virtual and override keywords because it inherits from a base contract and allows the same function to be written with its own logic and marked as override
1 Like

1. When should you put the virtual keyword on a function?

It’s used when a inherited contract can override that function.

2. When should you put the keyword override on a function?

It’s used when that function can override the same function from a parent contract.

3. Why would a function have both virtual and override keywords on it?

A function can have both override and virtual keywords. If that function can override the function in the parente contract and can also be overwriten

1 Like
  1. When should you put the virtual keyword on a function?
    A virual function is a based class function which is could be override by its sub class.

  2. When should you put the keyword override on a function?
    It means the function is overriding a virual function in its super class.

  3. Why would a function have both virtual and override keywords on it?
    That be that function is overriding a function is super class while being able to be further overriden by its subclass.

  1. When should you put the virtual keyword on a function?
    You can do this when it’s a transfer function and when you want it to be overridden by a derived class.
  2. When should you put the keyword override on a function?
    You should put the keyword override on a function when you want to override a base function that is marked as virtual. This means that you want to change how the function is implemented in the derived class.
  3. Why would a function have both virtual and override keywords on it?
    A function would have both virtual and override keywords on it when the function is overriding a base function that is also virtual.
  1. When you allow the function to be overridden in an inheriting contract

  2. When your function overrides an existing (virtual) function present in the parent contract

  3. When the function overrides the one from a parent contract but can also be overridden in an inheriting contract

  1. When should you put the virtual keyword on a function?
    A: when you plan on overriding/modifying the functions in another contract

  2. When should you put the keyword override on a function?
    A: when you need a want to override the functionality of a function with the same name that has the virtual keyword from an imported contract

  3. Why would a function have both virtual and override keywords on it?
    A: a function would have override and virtual when it is overriding a function from an inherited contract and is made to be overridden in another contract.

1. When should you put the virtual keyword on a function?
To indicate in the parent/base contract’s function definition that the child/derived contracts can override it’s behaviour.

2. When should you put the keyword override on a function?
To indicate in the child/ derived contract’s function definition that this function overrides parent/base contract’s function behaviour.

3. Why would a function have both virtual and override keywords on it?
To indicate that this contract’s function overrides parent/base contract’s function behaviour and also allows its child contracts to override its functionality.

  1. When you want any contract that inherits from the contract to be able to override the function
  2. When you want to override a virtual function from the inherited contract
  3. When a contract is overriding a function it inherits AND it wants to allow inheriting contracts to override it
  1. When I want a function of a base contract to be overridden in a derived contract.
  2. When I want to override a virtual function of a base contract in a derived contract.
  3. When the function overrides a virtual function in the base contract and also allows a function of a derived contract to override the function again.
  1. When should you put the virtual keyword on a function?

When its behaviour may be overriden by an inheriting contract.

  1. When should you put the keyword override on a function?

When it is overriding the behaviour of an inherited (virtual) function.

  1. Why would a function have both virtual and override keywords on it?

When it is both overriding inherited behaviour (e.g. from an interface contract) while also allowing inheriting contracts to further alter that (already-modified) behaviour.

2 Likes
  1. When should you put the virtual keyword on a function? if you want your function to be override when a base contract inherits your function.

  2. When should you put the keyword override on a function?
    when you want to override a function from the inherited smart contract.

  3. Why would a function have both virtual and override keywords on it? if you want the overridden function to be able for other smart contract that inherit from this contract to be able to override.

2 Likes