#50 Multiple Inheritance in Java

Поделиться
HTML-код
  • Опубликовано: 19 ноя 2024

Комментарии • 24

  • @abhineshwarjaiswar2913
    @abhineshwarjaiswar2913 4 месяца назад +6

    please keep making such courses... so glad that i discovered a creator like you...

  • @sohampatel-bm7gt
    @sohampatel-bm7gt Год назад +4

    You should have put these on the very beginning. The video of packages also. This helps while making and arranging files while making notes according to the topic. In java I find very difficult how to arrange and make notes in Java for different topics. Do each class we have to make different java file then why multiple class concept is used.

  • @kvelez
    @kvelez Год назад +5

    public class Main{
    public static void main(String[] args) {
    SciCalc obj = new SciCalc();
    System.out.println(obj.add(8, 3));
    System.out.println(obj.mult(8, 3));
    System.out.println(obj.sub(4, 9));
    System.out.println(obj.div(4, 9));
    System.out.println(obj.powered(7, 2));
    C letter = new C();
    letter.toString();
    new B();
    }
    }
    class A{
    public A(){
    System.out.println("Hello from A");
    }
    }
    class B extends A{
    public B(){
    super();
    System.out.println("Hello from B");
    }
    }
    class C extends B{
    public C(){
    super();
    System.out.println("Hello from C");
    }
    }
    class Calc{
    public int add(int n1, int n2){
    return n1 + n2;
    }
    public int sub(int n1, int n2){
    return n1 - n2;
    }
    }
    class Advanced extends Calc{
    public int mult(int n1, int n2){
    return n1 * n2;
    }
    public int div(int n1, int n2){
    return n1 / n2;
    }
    }
    class SciCalc extends Advanced{
    public double powered(int n1, int n2){
    return Math.pow(n1, n2);
    }
    }

  • @jagrutiacharya2083
    @jagrutiacharya2083 Год назад +13

    I think multiple inheritance is supported by interfaces in java.......how and why??

  • @ooogabooga5111
    @ooogabooga5111 6 месяцев назад

    You should have talked about how C++ solved this ambiguity problem,
    For anyone who is curious, C++ and other languages which support multiple parents in inheritence, uses function overriding to call the derived class method and then inside there you can use the method of A, B, or both, and include your derived class logic too inside it. This will look like,
    class AB extends A, B{
    func(){
    A::func();
    B::func();
    // your logic here
    }
    }

    • @disc127
      @disc127 6 месяцев назад

      why should he talk abt c++ in a video for java u dont have to be so cocky

    • @ooogabooga5111
      @ooogabooga5111 6 месяцев назад +1

      @@disc127 I'm not being cocky, I have no knowledge on C++ and I just started learning java 15 days before. I just googled. Its good to know the ifs and hows of multiple languages but you are correct he doesn't have to talk abt C++.

  • @luisantonio7191
    @luisantonio7191 9 месяцев назад +1

    Great class

  • @saicharanguggilam7162
    @saicharanguggilam7162 Год назад +2

    What about using default method of interfaces from java8 and calling them using interface.super.method..

  • @michaelakibira9005
    @michaelakibira9005 5 месяцев назад

    Very nice sir

  • @vishnusatheeshbabu6086
    @vishnusatheeshbabu6086 Год назад +2

    Is this also known as Diamond Problem?

    • @babaiiseuphoric
      @babaiiseuphoric Год назад +2

      Not exactly, the diamond problem is when B and C are extending from A and then again D is trying to extend from both B and C

  • @jeick3645
    @jeick3645 Год назад +1

    Master 😁

  • @venkysarman650
    @venkysarman650 8 месяцев назад

    End twist 😂

  • @ganeshpatil7489
    @ganeshpatil7489 11 месяцев назад

    Hii, I have a doubt plz someone reply and resolve
    If there is a same method in both the parent classes then it will create ambiguity. Even if there are no any same methods in both the parent classes then also it is giving error?
    WHAT IS THE REASON BEHIND IT?

    • @prajwalpatil6597
      @prajwalpatil6597 11 месяцев назад

      As of your code.. The same method name problem can be solved by METHOD OVERLOADING where as the problem could be in your object creation.

    • @mattasaikiran4812
      @mattasaikiran4812 2 месяца назад

      Because multiple inheritance is not possible because of the constructors in class not because of the same methods. That is the reason we don't have constructor in interfaces.

  • @farhodbekxamidov2013
    @farhodbekxamidov2013 10 месяцев назад

    👍

  • @davidking4849
    @davidking4849 4 месяца назад

    My Question: Can method overloading solve this ambiguity problem?
    Example
    class Mobile
    {
    brand;
    price;
    network;
    public void call() {
    print("Calling...")
    }
    }
    class SmartPhone
    {
    schoolContacts; // ← a database of my networks at school
    churchContacts;
    public void call(String schoolContacts) { // ← method overloading
    print("Calling..." + name of the person I am calling)
    }
    public void call(String churchContacts) {
    print("Calling..." + name of the person I am calling)
    }
    }
    // multiple inheritance
    public class Apple extends to SmartPhone, Mobile // assuming this syntax works
    {
    public static void main(String a[]) {
    // assuming I create the objects using appropriate classes
    person1.call()
    classmate2.call(schoolContacts)
    coordinator.call(churchContacts)
    }
    }

  • @MMNadaf-g5e
    @MMNadaf-g5e 27 дней назад

    If there is problem , lets remove the feature instead of finding solution.🤣🤣

  • @jagadeeshp1163
    @jagadeeshp1163 9 месяцев назад

    They will be happy 🤣🤣🤣🤣

  • @futuristictechnology..531
    @futuristictechnology..531 Год назад +1

    gadde multiple inheritances nahi hota hai java me

    • @rahulpatnala3242
      @rahulpatnala3242 Год назад +9

      abey gadde, sir bhi voi bholra hey, java mey multiple inheritance kyu naye hota hey and he is explaining the reason behind it, agar english naye atta tho aur eek channel dekhlena, don't comment before listening the full video