Java Tutorial For Beginners 25 – Inheritance in Java

java inheritance constructor
java inheritance vs interface
java inheritance static variables
java inheritance static methods
java vererbung
java subclass
java extend class
java class declarationjava inheritance example
java inheritance example program
java polymorphism
java inheritance constructor
java multiple inheritance
java inheritance interview questions
java inheritance pdf
java inheritance definition

Comments

Dinesh Sevalia says:

There is some audio problem +ProgrammingKnowledge

Hong Ln says:

why we need to set those two variables “protected” instead of in normal form, such as int height; int width?

Kurt Mani says:

Enjoying the tutorials very much.

Shimanto Akbar says:

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

ty houge says:

My left ear enjoyed this!

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

House of Doom says:

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)?

Oliver Waller says:

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(System.in);
double user_input_rec_height = scan.nextDouble();

System.out.println(“Enter width of Rectangle”);
Scanner scan1 = new Scanner(System.in);
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());
System.out.println(“——————————“);

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(System.in);
double user_input_tri_height = scan.nextDouble();

System.out.println(“Enter width of Triangle”);
Scanner scan3 = new Scanner(System.in);
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());

Rishabh Srivastava says:

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.

rahat nagpal says:

can u provide a small project that someone is able to make after watching your videos.. so that i can know how much proficiency i have in java

Mohammed Kalache says:

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

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.

Omar Taha says:

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

GoodGameYourDead - Minecraft And More says:

FIX YOUR FREAKING SMOKE DETECTOR

ProgrammingKnowledge says:
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.

ThatsRight says:

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

Christopher Murray says:

You should change the batteries in  your smoke alarm.

Android says:

Battery, Mic Please fix it..

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?

Jorge Jaramillo says:

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

Tabish Khan says:

Excellent videos. Kindly look into the audio issues, please. :)

navaneetha krishnan says:

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

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!

Max Hart says:

What’s with the 1 fps???

Umut Özdemir says:

dat nois makes me sleepy m8

lance delacruz says:

rec.set_values(10, 10);
tri.set_values(10, 10); cant work, on the problems tab it says:Description Resource Path Location Type
The method set_values(int, int) is undefined for the type Rectangle Class6.java /JavaProject6/src/package6 line 11 Java Problem

Pranjal Pathak says:

You need to be one ear deaf to listen to this fucking shit tutorial.

Likhit Reddy says:

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

Gerardo Olvera Puente says:

Really good videos, thanks dude!

Pinkk Wormm says:

i was so angry ,I almost destroy my left headphone…and yea…you ware

JP Nuqui says:

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

mohit saraswat says:

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

Anisha A says:

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

Rishi Rana says:

hey for the past couple of videos theres static in the right side for sound. the only sound coming is from the left. thank you 

Maknah says:

Is MyClass the Runner?

anudip dey says:

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

BEERS 'n GEARS says:

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.

Kyle Fitz says:

This dude swallows too often..

Aquieb Shaikh says:

volume quality is low it sucksss..

Joshua Bramble says:

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

E Kennedy says:

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

Vaishnu Reddy says:

can u upload more videos in java

sahej manchanda says:

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

Angel Hadzhiev says:

Bro i can tell you that you explain everything better than my professor 😀 i love your videos :)

Mohammad Alam says:

Tutorials are very good but some background noise, still it is free tutorial. :)

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours