Default Method Definition in Interface | Java 8

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

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

  • @saadiyafourie
    @saadiyafourie 6 лет назад +3

    I am SO GRATEFUL, thank you very much. Well explained and clarity achieved :)

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

    please make a video on when to use abstract class .when to use interface.

  • @navneetkumar6538
    @navneetkumar6538 17 дней назад

    very good

  • @nikhilratnalikar3914
    @nikhilratnalikar3914 3 года назад

    really thanks it helped a lot!!! you are awesome

  • @kritikagupta8794
    @kritikagupta8794 4 года назад +1

    I have 2 questions
    1) why we have to define that method in interface only , we can define method inside implemented class only?
    like message method with body can be write inside implementation class AndroidPhone, there will be no change in interface then
    2) if we want to enhance or add something in default method in implentation class, can we do that?
    Can we override default method too?

    • @kshitijsinghsomvanshi
      @kshitijsinghsomvanshi 3 года назад

      1) See you are modifying your existing functionality right. What if you don't want to break your existing classes while still adding new features(methods) in interfaces. I hope this solves your confusion.

    • @kshitijsinghsomvanshi
      @kshitijsinghsomvanshi 3 года назад

      2) yes default method can also be overriden.

  • @avinashkesarla3261
    @avinashkesarla3261 7 лет назад +2

    If we are able to define methods in the interface itself then what would be the difference between the abstract class which has concrete implementation and interface where we do have default definition of the method!

    • @georget10i
      @georget10i 6 лет назад +1

      avinash kesarla Abstract classes and interfaces have different purposes. With abstract class you have inheritance and the sub class inherits from abstract class (there can only be one abstract super class that the sub class inherits from, you cannot inherit from multiple super classes). Interface provides multiple inheritance. You implement an interface(s), and the only stipulation is that you must implement (and define) the interfaces methods. So think of an interface like a contract that takes hierarchically unrelated classes and creates a relation between them,a super class for unrelated classes. With abstract class there is a logical hierarchy, that's the most important part.

  • @malayalitravelsuk
    @malayalitravelsuk 4 года назад +1

    Why do we do like this :-
    List numList = new ArrayList();
    and why not
    ArrayList numList = new ArrayList();

    • @adarshverma3372
      @adarshverma3372 3 года назад

      it's simply matter of choice both will work

    • @ananyadwivedi5518
      @ananyadwivedi5518 3 года назад +4

      Using List as the reference type helps when you have to change the collection type of the reference
      for eg.
      List numList = new ArrayList();
      now if you want to use numList as a reference to some LinkedList you can do it directly without
      creating a new reference because List is the parent interface of both ArrayList and LinkedList.
      numList = new LinkedList();
      So it is a way of generalization and not specialization. Hope this helps.

  • @N63B44TÜ
    @N63B44TÜ 5 лет назад

    great like always!

  • @saikumar-kk1kh
    @saikumar-kk1kh 10 месяцев назад

    what about static method in Interface? do video for also??

  • @rqiambairik5707
    @rqiambairik5707 5 лет назад

    thank you for explaining .

  • @rupalipatil6288
    @rupalipatil6288 6 лет назад

    Is default is only keyword ...or it's access modifier is also default ?

  • @saikumar-kk1kh
    @saikumar-kk1kh 10 месяцев назад

    As a Career GAP Candidate StartUp Companies Lo Job Ela Techukovaalo Cheppandi Sir (or) Mam🙏🙏🙏??
    As a Career GAP(6 years) Student How to to get Java Developer Job in this Year 2024???
    Hi, I have a 6 years CAREER GAP. how can i get JAVA DEVELOPER Job in 2024 ???
    hi bro , 😭😭Naa Friend Okariki OLD UAN number activate kaavatledhu😭😭, Error: 🙏🙏🙏Basic Details like Name, Aadhaar & DOB are mismatched ani Vastundhi🙏🙏🙏 Bro..???
    hm alage, within seconds lo (Vs Code) and (Chrome tab) ela change avutunnayi Bro, Please tip cheppu.
    Two companies(XYZ & IJK) lo job vachindhi fake pettanu & alage 1.5 months 2 Companies lo Work Chesanu, Now i am looking for Job, my doubt is Those 2 companies are creating my pf or Not? further in future is it Effect my carrier?

  • @Raj_Gada
    @Raj_Gada Год назад

    if 2 interfaces have same method names but do different functions and a class implements both the interfaces then which method will it call

    • @PcDoc-c9g
      @PcDoc-c9g 2 месяца назад

      class method

  • @crazyvideos7628
    @crazyvideos7628 6 лет назад

    Why we are not declared that call method as default that is also by default public/abstract

  • @adarshverma3372
    @adarshverma3372 3 года назад

    here default is a keyword or an access specifier ?

    • @ananyadwivedi5518
      @ananyadwivedi5518 3 года назад

      yes its a keyword, access modifier of all the type of methods that is abstract, static and default methods is public by default. Hope this helps.

  • @sairawadwa3774
    @sairawadwa3774 6 лет назад

    Sir can we use instance variables in default interface.??

  • @dhoniramakrishna120
    @dhoniramakrishna120 6 лет назад

    sir if u override object class methods in interface we will get compile time error ?

  • @justfeelit6619
    @justfeelit6619 5 лет назад

    Can we have more than one default methods in interface? if default method we are defining in the interface it seems like same in the abstract class, what would be the difference between interface and abstract class in java8

  • @whatevergina9401
    @whatevergina9401 3 года назад

    Why is the ducking screen black

  • @asennikolaev8616
    @asennikolaev8616 8 лет назад

    how you comment 4 rows at the same time , and how you uncomment them ?

    • @rsbalhara11
      @rsbalhara11 8 лет назад +1

      Use Ctrl + SHIFT + L which will open a list of all major shortcuts for eclipse.