Inheritance

Lets Kode It
A free video tutorial from Lets Kode It
Anyone can code - Changing Lives Everyday
4.5 instructor rating • 8 courses • 87,935 students

Lecture description

You will learn inheritance concepts in Java programming language

Learn more from the full course

Selenium WebDriver With Java - Novice To Ninja + Interview

Join the "Top Rated #1 Best Selenium Course"-Basics To Advanced Level With POM, Grid, Maven, GitHub, Jenkins, Interviews

43:34:03 of on-demand video • Updated August 2020

  • ***** At the end of this course, you will have detailed understanding of Web Automation Frameworks
  • You will be able to EXPLAIN, DESIGN and IMPLEMENT structured AUTOMATION FRAMEWORKS using Page Object/Factory Model
  • *** In-depth understanding of Selenium WebDriver CHALLENGES with real time examples
  • You will be able to implement CONTINUOUS INTEGRATION TESTING using JENKINS
  • ***** We have 10 dedicated INSTRUCTORS to help you with queries within 24 HOURS, resume preparation, Interview questions
  • You will be able to perform CROSS-BROWSER testing using SELENIUM GRID
  • You will be able to create GREAT LOOKING REPORTS using the best advanced REPORTING TOOL
  • You will have complete understanding of TestNG Framework
  • ***** You will have excellent command on Build Management using MAVEN
  • ***** You should be able to lead any Selenium Automation Project from scratch on your own
  • ***** You will have understanding of Behavior Driven Testing Using CUCUMBER, Gherkin language
  • ***** You will be able to understand and write efficient testing code
  • You will have required skills to automate any web application
  • You should be able to verify Data Integrity with the GUI of the application
  • Additional Knowledge of running Performance tests with Selenium WebDriver Automation
  • With all this knowledge gained, you should be easily able to clear Selenium Automation interviews
English Otherwise. Welcome back to the series. So today we going to discuss a concept called inheritance. So what does inheritance means. And explain this using the program as well. It does give you the definition so it just sounds like a word right. So we inherit something from our parents of somebody's experience. Tell us what you would see the kids had toward. So we had certain properties from our parents right in our life. Similarly in Java a class can be inherited from a different class so that means the divide class the inherited class becomes a subclass to the class from which it was inherited. And the main class that comes up in class are superclass. So what happens after inheritance is certain fields that are defined in the parent class are methods that are defined in the painting class can be used within a subclass which is the inherited class. So those instance variables and those methods can be used. Which means the class inherited those properties those methods from the parent class. And that's the simple concept of inheritance. So let's go ahead and see it with the example. I'm going to create a new class called can read them all and see. Right now if you see this is inheriting so not inheriting but the symbol is object grade so which is an ultimate class for every class That's in that's in the back of dowered our. A in class. Every class has access to the access to some methods in that object class. Now let's ignore it. I know what you are you'll you'll understand it later. So I just created this class. And let me create another class maybe we. Cars are always the favorite topic. So I don't need them in my trendsetter. And we created the class also. All right. So in my college method let me make some in my class causelessly and make some methods let's say public wide and cories peed. That's corner and we Lamine creator and also end the hair loosely plus plus and see so well as to increase in speed. That should be good right. So let me create a similar method to see decrease speed and speed minus minus. So there's no right to speed plus plus it's going to increase increase the value of speed variable decreasing speak that the functionality of a car I would begin to increase the speed or decrease their speed. Now we have a variable also with the name speed. Now what happens. Let me make one more class and that class. My favorite one BMW. I can either specify here the name of my superclass which is going to be cars or if not then I can leave it like that also. And I say a key word expense cars. So this car is the class that we created here. Let me create a construct of public cars and something like B. Maybe the default speed. So I work and study speed and maybe let me call it study sleep. So it's gone I said to speed go study the study speak. That's it. So what I'm doing in the constrictors setting my speed to start speed in my BMW class all that we need to define a constructor for this also. And this is the construct that is not applied because it extends. It extends the superclass so public but the blue and read let's see or we can know what we can. We don't even need this we can just say this is like super and just give the way. So Seubert means it's called access the superclass. And it's just going to get the variables so deep I can see God speed. Instead God speed. So what this does is it's got to get the constructor from my class and it's just going to give this value there and it's gonna set it. So I'm just going to give the value from this class and is going to call the constructor from a superclass the SuBo is the key word which is actually used to access anything from the parent class which is my current class. So now what I can do is so let me create few objects in this main class which is inheritance temo. So let's call karst see one equals two new cards and limit game was played and speed equals to zero . And we pass speed here. And what else can I do. I just want a card and maybe see one dot increase speed. So let me run it now. What happens it's is increasing speed. How I can utilize these things inside my BMW class. Now that's the question. So let me call these things and say that what I can do is I can simply first of all I utilize the construct from my bidding class. Now what I can do is I can just override the methods that are implemented in my class and do my subclass . What the wording means is simply I can use these methods and change the functionality if I want to use the similar functionality. I can do do that also but for that I don't need a method inside my subclass. But what I can do is I can override the functionality of this method so I can define the same method inside the BMW class with the same signature and I can override the functionality I can change the functionality there. So what I can do is that I can type in myself like a public wide and an increase in speed and speed that I can do that or I have one more way that I can simply or I did just right click go to source and or read implement methods. What it does is it shows me the parent class because it's extended from the task class that shows me the methods inside the car class. If I don't or I just increase speed I would click on that and click OK. See it all right said. It just says public wide increase speed with the notation or right and there are two to do so stop right now. Just calling the increase be omitted from the superclass. So right now it's going to perform the same functionality. So let me do one thing. Let me create increasing speed of cars of cars. So you know the difference. Now let me read one more. We have to be one or maybe the new one equals two new BMW. Let me give a speed here. If I do that BMW 1 Godard increase speed what does it do right now. Let's see if I run this main class it says increasing speed of cars. It's called To dance and ski Ingredion speed of course because first time it's gone from here. Second time it's called from here body. It call the same method. Increasing speed of course because I'm just calling this hoopla increase speed. What I can do now that I can actually speed I can do I can do this cycle. C So increasing is the end of the interview. I can do this. So let's say I've done this now. And what happens if I run the score now for the first one it is increasing speed of cars because this is the object reference from the car's class. The second one is from the BMW class which is increasing speed of BMW. So if you guys noticed that this has already done the original increase speedometer and I have implemented a new functionality right here. So this is Skoll inheritance. What else we can do. Get in Hadad all those fields that's defined in the costless beginning. How did the speed variable began how did both of these methods are all Limited's actually which are defined in the costless mostly And what what else we can do is we can define new mentor inside it. So let's say I have some specific functionality probably wide and maybe heads up this really the navigation which is new in BMW. So I have this functionality which is new in BMW and maybe not in most of the cars some cars are given now but not in all the cars so I will implement this functionality for my BMW class. So what I would say is we have new specific functionality. So I can call this using a b w one dot B and in my head subdiscipline navigation right. If I run the code now it is the end of this specific functionality. But no these guys I cannot call this method from my seat if I do this. No heads up display navigation methods available to my class class because that appeared in class. So subclassed has the opportunity to use the obedience class methods but being in class cannot utilize the subclass method. So I can only call it in class methods which are defined in that I cannot use the subclass methods for the painting class. So these are the few things that they can do in inheritance and it's pretty useful sometimes to be Harrower like this is an obligation that they cause and we have different make and models of the class. So there are some specific functionalities like every cloud. Every car has to restart an engine and start an engine. Increase Increase speed and those kind of things. All these functionalities can be inherited took all the different classes which are different cars. Of BMW all the basic functionality is can be inherited from the costless and then the new functionality which is specific to BMW can be implemented in the BMW class similar if we have in my city are already on or something else. So this is the benefit of using inheritance. That's all for today guys. I think it's pretty much true about our brand. All you need to do is just create some small classes like this and do some practice. That's all. And then in next tutorial will cover your daily deals in Java. Thanks for listening guys. Thanks