What does the keyword virtual mean in the method definition?
The method can be over-ridden.
Can you declare the override method static while the originalmethod is non-static?
No, you can’t, the signature of the virtualmethod must remain the same, only the keyword virtual is changed tokeyword override.
Can you override private virtual methods?
No, moreover, youcannot access private methods in inherited classes, have to be protectedin the base class to allow any sort of access.
Can you prevent your class from being inherited and becoming abase class for some other classes?
Yes, that’s what keyword sealedin the class definition is for. The developer trying to derive from yourclass will get a message: cannot inherit from Sealed classWhateverBaseClassName. It’s the same concept as final class in Java.
Can you allow class to be inherited, but prevent the method frombeing over-ridden?
Yes, just leave the class public and make themethod sealed.
What’s an abstract class?
A class that cannot be instantiated. Aconcept in C++ known as pure virtual method. A class that must beinherited and have the methods over-ridden. Essentially, it’s a blueprintfor a class without any implementation.
When do you absolutely have to declare a class as abstract (asopposed to free-willed educated choice or decision based on UMLdiagram)?
When at least one of the methods in the class is abstract.When the class itself is inherited from an abstract class, but not all baseabstract methods have been over-ridden.
What’s an interface class?
It’s an abstract class with public abstractmethods all of which must be implemented in the inherited classes.
Why can’t you specify the accessibility modifier for methodsinside the interface?
They all must be public. Therefore, to preventyou from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it’s public bydefault.
Can you inherit multiple interfaces?
Yes, why not.
And if they have conflicting method names?
It’s up to you toimplement the method inside your own class, so implementation is leftentirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data,but as far as compiler cares you’re okay.
What’s the difference between an interface and abstract class?
Inthe interface all methods must be abstract; in the abstract class somemethods can be concrete. In the interface no accessibility modifiers areallowed, which is ok in abstract classes.
How can you overload a method?
Different parameter data types,different number of parameters, different order of parameters.
Add a Comment
Manish Dabasleft a comment
anshulshrivastava_214393left a comment
uma_eveangelinleft a comment
meens174left a comment
bbnayakleft a comment