Suppose, We have class A and class B having same method. class B inheriting from A. class A not defined virtual that method but Class B define override, then what will happen?
Ravi Kumar
Program will not compile generate error like; Error: Class B cannot override inherited member 'Class A' because it is not marked virtual, abstract, or override.
You can only override the virtual methods.
It will give a compilation error. Error : 'ClassB.Function()': cannot override inherited member 'ClassA.Function()' because it is not marked virtual, abstract, or override
Method of class A is hidden now and method of class B is invoked when called.
No Suitable method found to override
it will give compilation error...
I think you must be create virtual method in Class A than you will be use override method in derived class with out it Compilation Error is occur.
Error : cannot override inherited member ,because it is not marked virtual, abstract, or override.
metod overiding
In C# virtual is just optional...still it ovveride the method present in classB
here throw Exception, bcz, if base class have member method which does not marke as a virtual or abstract so compiler does not allow we go for in derived class a override that member method which is non virtual or non abstract.so if we want override those method then we have must go for that member method mark as a virtual or abstract. keep in mind.
an warning is shown
will throw the exception "cannot override inherited member bcoz it is not marked as virtual in a parent class
here throw Exception, bcz, if base class have member method which does not make as a virtual or abstract so compiler does not allow we go for in derived class a override that member method which is non virtual or non abstract. keep in mind.