Java Tutorial # 18 | Abstract classes and Methods in Java -Java Beginners tutorial by Java9s

Home/Programming Video Tutorials/Java Video Tutorials/Java Tutorial # 18 | Abstract classes and Methods in Java -Java Beginners tutorial by Java9s

Java Tutorial # 18 | Abstract classes and Methods in Java -Java Beginners tutorial by Java9s

FavoriteLoadingAdd to favorites

This video tutorial explains about the Abstract classes and Methods. Abstract Methods does not have implementation and Abstract classes cannot be instantiated. I have explained about the importance of Abstract classes and how sub classes should override the Abstract classes methods.

Java468x60
By | 2017-06-22T02:37:21+00:00 June 22nd, 2017|Java Video Tutorials|32 Comments

32 Comments

  1. itsdannyftw June 22, 2017 at 2:43 am - Reply

    1. The SamsungGalaxy class contains an abstract method, and thus the class itself should be abstract as well (so that the subclass can fulfill the contract of implementing the chat() method).

    2. The abstract method storeContact() is never implemented in any of the subclasses. This is illegal.

    3. There is no return type for the abstract method storeContact(). This is syntactically illegal.

    4. The calculator() method is not an abstract method, and thus an implementation (which in this case, does nothing) is provided. However, it has the final keyword set, yet the SmartPhone subclass that extends the abstract class containing the calculator() method provides an implementation for the calculator() method. This is illegal because a method declared final cannot be overridden.

  2. sandip bhattacharjee June 22, 2017 at 2:43 am - Reply

    1. The StoreContact method belongs in the Mobile abstract class should have a return type.
    2. The Smartphone class can not override the implementation of the final void calculator method of the Mobile class 
    3. The concrete class SamsungGalaxy is miss the implimentation of the abstract method StoreContact belongs in the Mobile class.
    4. The concrete class SamsungGalaxy is miss the implimentation of the method public void chat(), belongs in its own Class.
    So SamsungGalaxy class should be declare as abstract or it should implements all the abstract methods of its super class. 

  3. toybuck dot June 22, 2017 at 2:45 am - Reply

    finally good english

  4. satyamanyu kumar June 22, 2017 at 2:46 am - Reply

    Sir dis is satyamanyu,may u tell me what’s d basic difference between interface & abstract class,i mean some authors say tat interface can not contains any concrete method,it only contains abstract method ,but abstract class may contain,is dis true,may u tell me wat’s d basic difference between abstract classes & interface?

  5. Abhi Mishra June 22, 2017 at 2:47 am - Reply

    Great job done..Thnx million times.

  6. java9s June 22, 2017 at 2:48 am - Reply

    You can declare any number of methods in an abstract class which can be abstract or non abstract ones

  7. shruthi reddy June 22, 2017 at 2:49 am - Reply

    1) Cannot override the final method from Mobile
    2)The type SamsungGalaxy must implement the inherited abstract method Mobile.storeContact()
    3)chat method requires a body instead of a semicolon

  8. Rahul Krishnan June 22, 2017 at 2:50 am - Reply

    Hi Srinivas, great lecture. Can you please provide the link to download the pdf of this tutorial? I can’t find it on the site.

  9. Raymond Sarreal June 22, 2017 at 2:54 am - Reply

    can we download the ppt ?

  10. Kiran Sreenath June 22, 2017 at 2:55 am - Reply

    1) Void Calculator method in smartphone class cant be overrided from its superclass method , as void calculator is a final method in the mobile class.
    2) The samsung galaxy class has to be a abstract class as it has a void chat(); abstract method in it or provide some implementation to void chat() method and make it concrete method.
    3) The abstract method storecontact () is not implemented in any of the subclass.

  11. mehmet oymak June 22, 2017 at 2:56 am - Reply

    awesome…Sir I have a question. How does java know the arbitrary abstract method names? Suppose that  I use an arbitrary method name "gosterLan()"  instead of draw() or render  etc.. any ideas?

  12. Danish86able June 22, 2017 at 2:59 am - Reply

    First thing is that you can’t override a method which marked as final so method calculator can’t be override in the SmartPhone class.Second thing is that there is a implementation of call method in SmartPhone class but no implementation for storeContact method it must be override in SmartPhone class.

  13. Prathamesh Rane June 22, 2017 at 3:00 am - Reply

    1.there is no return type defined for storeContact() method in mobile.
    2.you cannot override method marked as final in subclasses ie. calculator()
    3.storeContact() method is not overridden in SmartPhone class.
    4.there is no implementation given for chat() method in SamsungGalaxy class, it has to be abstract.

  14. Raymond Sarreal June 22, 2017 at 3:02 am - Reply

    i checked it in java9s.com but i cant download the ppt.

  15. Satoshi Chomsky June 22, 2017 at 3:04 am - Reply

    I found this helpful because you speak in a pace that I can handle — not too fast, not too slow. Just right for me. thanks.

  16. Kevin Boger June 22, 2017 at 3:06 am - Reply

    1. In the abstract class Mobile, the storeContact() method does not have a return type
    2. The SmartPhone class can not override the implementation of the final void calculator method of the Mobile class
    3. The concrete SamsungGalaxy class is missing unimplemented methods from the abstract SmartPhone and Mobile classes. There also needs to be an implementation for the public void chat() method.

    I hope I’m close 🙂

  17. Rasmi Ranjan Nayak June 22, 2017 at 3:10 am - Reply

    Excellent, Sir your voice is very clear and to the point… Kepp doing good work

  18. ajeet pal June 22, 2017 at 3:12 am - Reply

    1 erorr is abtract call mobile may be not should be contain final and abtract methods and there is no chat funcation
     

  19. Saurabh Joshi June 22, 2017 at 3:15 am - Reply

    AWesome sir keep it up #socialjava

  20. Charan Guru June 22, 2017 at 3:16 am - Reply

    sir , i m charan , i have few doubts … 1st of all u done a grate job!!!
    question :

    1) can we declare two or more abstract methods in non concrete class

    ex:
    public abstract class car
    {
    public abstract void hello();
    public abstract void hell();
    }

  21. Sachin Bansal June 22, 2017 at 3:16 am - Reply

    sir .. could you please list all the issues with this brain teaser so that we can cross-verify our observations .. 

  22. Siddique Hassan June 22, 2017 at 3:17 am - Reply

    Abstract class (Smartphone) that is extending Mobile class can’t implement any methods ( i.e. calculator and call) as it’s been declared as abstract. I’m not sure about SamsungGalaxy class as there is no class as Smartphone though its syntax is right. StoreContact needs a return type. Kindly correct if I’m wrong. 

  23. java9s June 22, 2017 at 3:18 am - Reply

    Here you cannot create an instance of bike as it is abstract. To override, the method need not be abstract, all it takes that the classes should be in inheritance(extends)

  24. Apurb Kumar Choudhary June 22, 2017 at 3:20 am - Reply

    Cannot override the final method from Mob

    The type Iphone must implement the inherited abstract method Mob.storeContact()

    And the chat method requires body instead of colons

  25. Charan Guru June 22, 2017 at 3:20 am - Reply

    2) if possible .. then how do we override a particular abstract method in concrete class out of all abstract method which r declared in non concrete class
    ex:
    public abstract class bike extends car {
    void hello(){
    S.o.p(" hello ");
    }
    public static void main(String g[])
    {
    bike g=new bike1();
    g.hello();
    }}

  26. Ramya Reddy June 22, 2017 at 3:22 am - Reply

    3. storeContact() needs return type ..

  27. Kishore Banala June 22, 2017 at 3:22 am - Reply

    Great Lecture. Its clear and precise. My personal feeling is that it could be even more better if you can use some IDE like eclipse to demonstrate the code part, as it checks for errors while coding.
    Thank you!

  28. /〈Krishna murthy〉/ June 22, 2017 at 3:28 am - Reply

    The issues with the code are::

    Calculator() of SmartPhone cannot be overridden because in superclass (Mobile) the method has been declared as final.

    Class SamSungGalaxy should be declared as abstract. The reasons are:
    1) Neither class SmartPhone nor class SamsungGalaxy implements all the abstract methods.
    2) Class SamsungGalaxy has method chat which did not implemented

    storeContact() of Mobile did not have the return type.

  29. Tali1562 June 22, 2017 at 3:29 am - Reply

    Thank you so much my friend!

  30. Zohaib Ahmad June 22, 2017 at 3:34 am - Reply

    For the Brain Teaser.
    1)The video chat method is not given any implementations in the SamsungGalaxy class.
    2) The abstract method storeContact is not being overriden.
    3) The Method Calculator which is marked as final is being overriden.

  31. Vivek ch June 22, 2017 at 3:34 am - Reply

    1. calculator() is a final method we can’t implement..
    2. chat method requires body …

  32. Danish86able June 22, 2017 at 3:35 am - Reply

    One thing more chat method require body because its a normal method.

Leave A Comment

*