Reputation: 1403
I'm trying to make spreadsheet with class/method modifiers. The spreadsheet itself can be located here, although I have some questions:
1) As I read, methods also can be sealed
, but what's the purpose of this? Protecting method against overriding?
2) Does fields also have to be abstract
in abstract
class?
3) Can virtual
method have body in defined object/class?
Upvotes: 1
Views: 837
Reputation: 12128
sealed
methods prevents further overriding down the inheritance chain. sealed
methods also need to have override keyword.
Fields cannot be abstract
. Field is a class level variable. You can't override that. Properties and methods can be abstract
, but doesn't need to.
The difference between virtual
and abstract
methods is that virtual method has an implementation. You can override that implementation in derived class.
Upvotes: 3
Reputation: 1063599
1: yes, exactly that; stopping a virtual method from being overridden again in a subclass
2: fields are never abstract; fields are implementation; nothing has to be abstract in an abstract class
3: yes, in that the virtual modifier is distinct from the abstract modifier. Both represent a virtual-method - the difference is entirely whether there is an implementation in the base class
Upvotes: 3
Reputation: 7202
Upvotes: 1