Part 34 - C# Tutorial - Problems of multiple class inheritance.avi

Part 34 - C# Tutorial - Problems of multiple class inheritance.avi

kudvenkat

12 лет назад

277,532 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@dennygamer9039
@dennygamer9039 - 17.04.2023 16:25

The diamond problem occurs in multiple inheritance when a class inherits from two or more classes that have a common base class. In such a scenario, if there is a method with the same name and signature in both the parent classes, the compiler cannot determine which method to use when the child class invokes it.

Type casting an object of a child class with its parent classes does not solve the diamond problem because it only changes the type of the object reference, not the object itself. The object still has all the methods and properties of the child class, and it is not possible to invoke a method from a specific parent class.

Type casting is useful when dealing with interfaces because interfaces define a contract that classes implementing them must fulfill. When a class implements an interface, it is essentially agreeing to provide a specific set of methods and properties defined by that interface. Since interfaces do not have any implementation, type casting can be used to obtain a reference to an object that implements a specific interface, allowing the invocation of methods defined by that interface.

In summary, type casting cannot solve the diamond problem because it does not change the methods and properties of the object. It can only change the type of the reference to the object. In contrast, type casting is useful in the context of interfaces because it allows the invocation of methods defined by the interface.



-Answered By ChatGpt

Ответить
@abdullahmohammad5613
@abdullahmohammad5613 - 14.04.2022 10:59

I really appreciate your review of previous concepts while you're introducing a new one. Go bless You!

Ответить
@saahilwrites8816
@saahilwrites8816 - 04.02.2022 17:17

Lanat hai

Ответить
@mnopqrst7284
@mnopqrst7284 - 10.10.2021 15:36

One cannot have more than one father.

Ответить
@vr.108
@vr.108 - 02.10.2020 11:14

Thanks Venkat

Ответить
@raghavendra5311
@raghavendra5311 - 14.05.2020 01:11

Kudvenkat you dont speak clearly and loudly. Speak clearly and your voice goes up and down so cant understand what you are speaking

Ответить
@suryakantasahoo279
@suryakantasahoo279 - 21.07.2019 17:12

There is no common method in two class .If i inherit both the classes to another class .Then there is no ambiguity problem. Then why it's not supporting multiple inheritance?

Ответить
@TAREKmohamedALAQSASoft
@TAREKmohamedALAQSASoft - 17.11.2018 12:25

why i don't use explicit like interface or use this C d = new D(); if i want to use method in C class ? is what i said is correct ?

Ответить
@microtech2448
@microtech2448 - 26.09.2018 20:44

No reply from Venkat on very general question which people have asked on multiple inheritance implementation as he did with multiple interface using type cast or explicit implementation ?

Ответить
@aaronaaronaaron5922
@aaronaaronaaron5922 - 28.05.2018 20:41

Sir, just THANKS again!!!

Ответить
@KMILIND
@KMILIND - 28.12.2017 00:55

Can't We explicitly specify which class method to invoke as we do it in case of interface?

Ответить
@jamesbond-cx2uh
@jamesbond-cx2uh - 23.12.2017 12:59

i thought it is impossible to inherit more than one class?

Ответить
@MilanSiddhpura
@MilanSiddhpura - 26.06.2017 03:12

nice tutorials....

Ответить
@makeafakesaytake7498
@makeafakesaytake7498 - 26.01.2017 00:05

so what will it print ?

Ответить
@sijimathew9982
@sijimathew9982 - 03.02.2016 19:21

nice tutorial.... you are great

Ответить
@anisali5
@anisali5 - 22.07.2015 11:51

what if you do the same as we done in Interface video by calling multiple inherit interface by naming method with interface name and using instance by type casting
for example
class B : A
public void b.print()
{
}

Ответить
@pankajkulkarni6456
@pankajkulkarni6456 - 30.06.2015 08:48

In case of diamond problem why can't we type cast object of class D with B or C to identify which method to invoke? Same way as we do it in case of interface.

Ответить
@vinothkumarsakthivel6870
@vinothkumarsakthivel6870 - 27.11.2014 14:28

@ Ravi Yadav G. When D class inherits from B and C taking scenario as you mentioned that both B and C has different methods and are not virtual and not overridden....assume tat if .net frame work allows it, it cant be hold true for the case that if class B and C has same method name ,since ambiguity arise which method to use..to make it easier for code writer they restricted like tat ..and also we cant restrict user not to have same method name .. since it may come from different projects ........

Ответить
@RaviYadavGv
@RaviYadavGv - 12.04.2014 20:29

Suppose in this Dimond problem 
If classA contains only one method methodA()
and ClassB:A contains only one method methodB()
and ClassC:A contains only one method methodC() these all methods are not virtual and not overriden then why we can't define ClassD:B,C like this. here where is the ambiguity

Ответить
@bobzarrabi0024
@bobzarrabi0024 - 10.12.2013 19:44

I understand that we can inherit multiple classes at the same time because like you said, it is kinda confusing to call which method. But why we cant do that ? 
B b = new D();
b.Print();
C c = new D();
c.Print();

Ответить
@nandinims9472
@nandinims9472 - 22.07.2013 19:00

That's the exact question. What is the reason behind c# not supporting multiple class inheritance?

Ответить
@Ayubajbnabi
@Ayubajbnabi - 26.06.2013 02:09

Great. Thanks.

Ответить
@saridhamanoharan9129
@saridhamanoharan9129 - 07.05.2013 15:15

Thank you Very much, you r one of the best teach in my life!!!!!!! Please post some of the videos on WPF.

Ответить
@guy11
@guy11 - 31.10.2012 19:53

your videos are amazing...

Ответить
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot - 14.09.2012 21:29

A class cannot inherit from multiple base classes at the same time, whereas a class can inherit from multiple interfaces at the same. So, since a class is capable of inheriting from multiple interfaces at the same, and if the parent interfaces happen to have a same method name, then the class can be explicit about which interface method it is implementing using explicit interface implementation. Whereas with classes, we won't ever run into this situation.

Ответить