Coding Fun Java Java Tutorial For Beginners 25 – Inheritance in Java

Java Tutorial For Beginners 25 – Inheritance in Java

★★★Top Online Courses From ProgrammingKnowledge ★★★
Python Programming Course ➡️ ⚫️
Java Programming Course ➡️ ⚫️
Bash Shell Scripting Course ➡️ ⚫️
Linux Command Line Tutorials ➡️ ⚫️
C Programming Course ➡️ ⚫️

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

49 thoughts on “Java Tutorial For Beginners 25 – Inheritance in Java”

  1. Autif Kamal says:

    The quality of the audio does affect the quality of the video. You should've addressed that. You seemed to entirely neglect them.

  2. which software you are using??

  3. De todas formas solo me funciona un audifono

  4. saniya .s says:

    Audible only in right ear👌

  5. Can we use perform as method

  6. Java is very smiliar with C#

  7. My right speaker is spoilt need to buy a new one

  8. Parijat Dhar says:

    Actually, this is an example of hierarchical inheritance as the super-class is inherited by both sub-classes.

  9. My left ear seem to enjoy the vid

  10. Sophia Man says:

    I am not the only one who looked for another pair of earphones. LOL.

  11. 安妮 says:

    Excellent example and very well explained! 👍

  12. User interface program in same method

    public class MyProgram{
    public static void main(String[] args) {
    rectangle rect =new rectangle();
    triangle triag=new triangle();
    System.out.println("The Area of Rectangle is: " + rect.Area());
    System.out.println("The area of triangle is: " + triag.Area());

    import java.util.Scanner;
    public class polygon {
    protected int length;
    protected int breadth;
    public void valset() {
    int l;
    int h;
    System.out.println("Please enter Length: ");
    Scanner a=new Scanner(;
    l = a.nextInt();
    System.out.println("Please enter breadth or height: ");
    Scanner b =new Scanner(;
    h =b.nextInt();
    length = l;
    breadth = h;

    public class rectangle extends polygon {
    public double Area() {

    public class triangle extends polygon {
    public double Area() {

  13. Is someone watching it in 2018? 😀

  14. nice tutorial, keep it up 👍🙂

  15. Maknah says:

    Is MyClass the Runner?

  16. Awesome Video man!! thanks a bunch, got me out of a pinch

  17. anudip dey says:

    Can I set the values of height and width in Polygon class and the sub classes can access it?

  18. Lisa Mango says:

    I thought my headphones were broken, so then I went on a 10-minute search to find other headphones, then realized they were broken too. Then I read the comments. Lesson: read the comments first.

  19. Kyle Fitz says:

    This dude swallows too often..

  20. Please watch my "How to replace the battery in your smoke detector FOR ABSOLUTE BEGINNERS."

  21. SUNGHYUN LEE says:

    Hi Guys.
    Does anyone know how to use a value from other Method (e.g public class int calculate() {})?
    How should i use the variable that was set in another method or class?
    Thanks all!

  22. you did not explain types of inheritance,
    why multiple inheritance is not possible..??

  23. Java says:

    In inheritance you can take the variable and method for other class and difference between interface is necessary use abstract you can only take the method, I´m right?

  24. Likhit Reddy says:

    please fix the audio, it is irritating while on the headphones.

  25. Hi ProgrammingKnowledge,

    While writing the code of inheritance I declared the method to set values in polygon as static and now I am getting warning at the variables being set as "can not make static reference to non static field height"

    Please see the code written by me for Polygon class:

    public class Polygon {

    protected int height;
    protected int width;

    public static void setValues(int l,int w)
    height= l; // warning "can not make static reference to non static field height"
    width= w; // warning "can not make static reference to non static field width"


    Once I remove the "static" keyword from setValues method the error is gone.

  26. dat nois makes me sleepy m8

  27. Why PUBLIC is not used in place of PROTECTED? And is there any difference in :- (a) public int height;(b) int height; is there any difference between (a) & (b)?

  28. volume quality is low it sucksss..

  29. Nadim Baraky says:

    There's a small issue in the area() in Rectangle class. You must cast the height*width to (double) before dividing by 2.
    Here by chance the result was true. If it were say 50.xx it'll be also 50. Since it's applying "Integer division" & then, returning it as a double.

  30. Get creative with it. Only a few hours in and I feel like I am learning quite a bit. Try getting user input for height and width like this one:

    public static void main(String[] args) {

    Rectangle rec = new Rectangle();

    System.out.println("Area of a Rectangle");
    System.out.println(" —————–");
    System.out.println("| |");
    System.out.println("| |");
    System.out.println("| |");
    System.out.println(" —————–");
    System.out.println("Enter height of Rectangle");
    Scanner scan = new Scanner(;
    double user_input_rec_height = scan.nextDouble();

    System.out.println("Enter width of Rectangle");
    Scanner scan1 = new Scanner(;
    double user_input_rec_width = scan.nextDouble();

    rec.height = user_input_rec_height;
    rec.width = user_input_rec_width;
    System.out.println("The area of the rectangle is " +rec.area());

    Triangle tri = new Triangle();
    System.out.println("Area of a Triangle");
    System.out.println(" <>");
    System.out.println(" [][]");
    System.out.println(" [] []");
    System.out.println(" [] []");
    System.out.println(" [] []");
    System.out.println(" [] []");
    System.out.println(" [][][][][][][]");
    System.out.println("Enter height of Triangle");
    Scanner scan2 = new Scanner(;
    double user_input_tri_height = scan.nextDouble();

    System.out.println("Enter width of Triangle");
    Scanner scan3 = new Scanner(;
    double user_input_tri_width = scan.nextDouble();

    tri.height = user_input_tri_height;
    tri.width = user_input_tri_width;
    System.out.println("The area of the rectangle is " +tri.area());

  31. Thanks for the videos , very helpful , just few comments.

    your voice is not clear not only because the left earphone error , you're far away from Microphone or it's not a good one.

    Also you repeat your self many times. sometimes it's helpful and other times it's very irritating.

    hope this series will improve and show us real java not only methods and calculations.

    we haven't any interface or display window.

    But in total it's a very helpful series and thanks for uploading this and share with us your experiences

  32. There is some audio problem +ProgrammingKnowledge

  33. E Kennedy says:

    These turorials have been great.  Thanks for the time you seent doing them.

  34. Please solve the sound problem. Otherwise the tutorials are awesome.

  35. why did u use it can be done without set values may be we have to set 1 by 1 in main thatswhy

  36. Do you hear the chirp sound every 37 seconds? Yes that is your smoke detector. It has a dead battery. Replace the battery…. jesus christ.

    Also, most of your video is in mono audio. What that means is that your voice only comes out of one speaker and static comes out of the other one. It is highly annoying, fix it.

  37. Bro i can tell you that you explain everything better than my professor 😀 i love your videos 🙂

  38. Tutorials are very good but some background noise, still it is free tutorial. 🙂

  39. ThatsRight says:

    U don't need to start with Protected… choose Private

  40. Omar Taha says:

    man plz fix your mic issue……….. your tutoriels are great but when we can hear them 🙁

  41. Max Hart says:

    What's with the 1 fps???

  42. Anisha A says:

    love this tutorial. but that smoke alarm is driving me nuts

  43. Thank you! I've been following since video 1. They have been so helpful!

  44. i wish i saw this videos before. after 30 hours my exam.

  45. Shireen Naaz says:

    I don't know why but this is only audible in right ear but not left,first I thought it's my earpiece fault,but it's working fine,please correct the audio settings of your video

Leave a Reply

Your email address will not be published. Required fields are marked *