Access Modifiers and Packages

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

Lecture description

You will learn about access modifiers and encapsulation 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 Hello Guys welcome back to the series. Today we're going to discuss about packages and access modifiers So let's first jump two words packages . What are packages you might have noticed some of you might have noticed that all the programs they're carrying are inside the fall packets that Eclipse creates for us what it does is package helps us in grouping of related types. What I would do I mean by type here types are different like all the classes all interfaces are all enumerations. So it helps us grouping of related classes related interfaces in the same packet. Let's say I'm working on so many products and I need to know where my program files are read. Where are they located in so many products so I what I can do have is like different packages created for different sort of files. Maybe my car's related files are going to be in one package and maybe in my automobile factory I have one. Trucks manufacturing unit so I'll have my trucks related files in one bag as those kind of things. So basically it helps us in managing and having a clear name space. So what we can do is I can just create one more package to show you how quickly create back again right click on the source new package and we'll i mean name me name it as all the more well and make sense . So from my last two Dorel let me just pull some of the classes to this Baggot Garson Maybe BMW to my automobile back engine eclipse will do the refactoring for us. So if you guys notice this inheritance do our job at last he stood in the default bagage these two glasses move to our mobile bacot. So what I could do this if I did these two statements important automobile DOD BMW and automobile cars automobile is the Baucus name. We have been Carse's the class filing. So that's what it is importing here to use the methods and variables from those classes in my head and then we do our job our class. So that's how a package is created and that's how a package is used in some other namespace. So now let's do one thing. Let's create one more class here to show you guys the access modifiers. Maybe the name of the x axis or the fly as a main method and I'm going I need here is maybe cause I'm just going to need the class object. That's it. So I don't really need that. So what I'm doing here is I'm just again creating an offense to my car's object. I'm not sure. Something to guys. You just need to double click them to reopen them. All right. Because the open files were in different product. So we need to reopen these files. Now see how these cleated So let me delete So how many types of access modifiers we have. We have private public producted and we have one last as no access modifier. And what a first show you guys what is a no access modifier which is let's define this in speed. I haven't defined any modifier right. Maybe before jumping to this let me explain you one modifier So you guys are pretty much familiar if you are noticing it and realize we are creating We are putting this public key word every method we are creating We are putting this public key word here that created this productivity word. So these key words are access modifiers. They limit the scope of these variables and methods where they can be busy when and where they can be accessible. So basically these are access Filofax. So when I do not put any access modifier. What does it mean when there's no modifier. It means that particular variable are a method or a constructor. Basically those are only a relabel in the same package. It's mostly with the variables and the methods plan. So my speed. I can pretty much use it inside the same backwards. So let Scarlett her in access the demo. Let's see if I can see one dot. Speed. Yes I can use it and I can set it to tell you how I will said it took 10 successfully so I can use this bead which is defined with no excess modifier in the class which is inside the same package. All right. Let's come to the next day which is private. So let me define Let me call it the same thing speed and just change the name just drive with speed . So you guys will be able to easily. Sorry it will go first and then me that type like that. So you guys know what's that daybook speed is just by the name. So let me now cried Here. See one dot. So what happened. My private variable is not visible here right. Yeah that's what we expected. Because I said private variables only in class by private variables private methods are only available in tasks that can not be used outside the class . There's one way if we really want to use it outside the class we can use all those and get them. We can maybe say public and wide and said But I read something like. And he may read and see by the read he calls to the speech. So when I'm sitting here using my public method. So I just created a public method to set my brain speed I can actually use this what I can do is see when I can use my method that I created set pirate speed and send maybe limit as 10. So now I've just said my private Brady bill with the help of the public sentiment. That's sound we pretty much used several methods and get methods to work with private instances private variables private members may as well be moved to other type maybe the public will say well let's call it Blake and Blake Read and wait a semicolon and let's see if I'm able to use it her dog or the public space. Definitely yes. So public speech is meant to you maybe and the public since it is public it is pretty much is available anywhere. Even if I go to my other classes in my other back it is I just need to import them and it should be available to open this class which is in boarding my car some BMW classes. I can pretty much use that as well. And so the public sphere is available here. And if you guys notice my speed once just speed without any modifier it's not really air in my head and small c c one dot speed is not available. So only public methods and public variables are available. And if you see public speed is available said private speed that matter most public this is available and the speed is available because that's public. That's it that's it that's all. Which is available in any other class which is outside the packet. Right. So no private variables no variables without access modifiers not available outside the bag. This is public. Maybe you may define a new We're in the job world with importing me backwards and class. All right the next and the last best product. So if I define them predictable you will grow tired tired and bored with speed. But it can do it's a reliable we're. So guys this variable are any method which is defined as predictor. So I have a method here. Decrease speed which is defined as predicted. Both of these things should be available anywhere in any class within the same package. That's one thing which is similar to existing one additional stuff that's reliable with the product type is there accessible to any subclass even if the subclass is outside of the package. So let's see them. They move us call them help us he runs DOD or product Goodspeed is available let's say maybe I'm using products that speed maybe as a speed limit. So it's available here if you see see when DOD decrease speed is available here. So both of these are defined as protected when this is protected it's available here. If I go in and start our let's see one dot product that's free it is not available. While I and my Lucrece field is also not available. OK guys. Increase speed is also not available because this class is not a subclass of my class class and it's outside of the of the automobile packets desists are really well to my BMW class there should be let's see if I call increase speed so I can call producted speed. Definitely less less because this is a subclass to my cross-class and also in the sites in the sim packets with my cost. So I am able to access this all day. I can also maybe create cars. See one equals new cars and I can also access my decreased feed because this is also declared as predicted and it's declared in automobiles are gas as Integrys Friedman. So we will do x us that BMW just because it's a subclass to my cost plus and exists in the same package . So guys if you will. Norris I don't know what they were made of reference to access the producted speed with evil. I can just use it to clean this up glass see I can use a dado in that subclause. That's the benefit of the product. But the thing is it's only available in the back garden the subclasses. So since I was not able to access this in my inheritance d'Amour and which is in a different baskets I want to show you guys the example of creating one more class maybe. Let's see on that last. And maybe we import our kids. So how do we import baggage on board two mobile cards. Are we going to see the card. It's only if we just wanted the car. All we can see are more will die scar color. To bring up everything within that or automobile package. So this device now when we get them here probably wide in cruise on. We need something different. And what do I need to see here. What's what all is unbelievable. Right. So let me create my instance cars see if one wants to kneel cars even DOT my public street is definitely liberal because it's public. What's next. My private speed is every liberal that's there. Let's call it turn. What next is available. Let's see. All very sorry. We'll make it as a subclass. We need to extend cars in order to make it as a subclass. And now let's see what else is available. Sorry it's late. My computer is getting slow. So if I just do that my product and speed is available you best Notice that this is available because when their class is a subclass of my class class window it's in a different package. I mean able to access my product that speed very well. So that's what I was telling you guys. I can pretty much access my predicted speed rable anywhere in the same bag kids are in a different Baggot if the class is a subclass to my cost just because they're good speed very well was fine in the cost plus. So this is pretty much that we want to discuss and seeing bad kids and in some classes that is the definition of that debatable. So desperate limits guys and I think this is quite a bit to absorb. All you need to do is some clatters to understand this too crabbed is there so many modifiers. Baghdad is just like some dummy code and try to access some variables some methods in different classes . You see some issues. This is all them work on them. Get your hands and do the practice and you should be OK. And also help know this could be good. So you guys can access it for school if you face any problems and post your questions in the discussion forum. I'll get back to you guys. And I would just strongly recommend those two factors will be so similar with these things and you sound important. Thanks guys.