#54 Access Modifiers in Java
Telusko
@teluskoAbout
Hey Aliens Welcome to Telusko! We create technical tutorials that take you from beginner to advanced level. You’ll find content on: Core Programming: Java (Beginner to Advanced), Python, JavaScript Frameworks & Tools: Spring Framework, Hibernate, Blockchain, Spring AI, AI Engineering Computer Science Essentials: Data Structures, Networking, System Design, and more Trending Tech: Cloud, Microservices, and beyond Alongside technical tutorials, we also share motivational videos and host sessions with leading industry experts. We don’t just stop at free tutorials—we also provide paid courses (live and recorded) and corporate training to help professionals and organizations upskill. So, whether you’re just starting out or sharpening your professional skills, there’s always something here for you. 📩 Business Inquiries: [email protected] 🎓 Explore Live & Recorded Courses: https://telusko.com/
Latest Posts
Video Description
Check out our courses: Java Spring Boot AI Live Course: https://go.telusko.com/JavaSpringBootAI Coupon: TELUSKO20 (20% Discount) AI Powered DevOps with AWS - Live Course :- https://go.telusko.com/AIDevOps-AWS Coupon: TELUSKO20 (20% Discount) Master Java Spring Development : https://go.telusko.com/masterjava Coupon: TELUSKO20 (20% Discount) For More Queries WhatsApp or Call on : +919008963671 website : https://courses.telusko.com/ Udemy Courses: Spring: https://go.telusko.com/udemyteluskospring Java:- https://go.telusko.com/udemyteluskojava Java Spring:- https://go.telusko.com/Udemyjavaspring Java For Programmers:- https://go.telusko.com/javaProgrammers Python : https://go.telusko.com/udemyteluskopython Git : https://go.telusko.com/udemyteluskogit Docker : https://go.telusko.com/udemyteluskodocker Instagram : https://www.instagram.com/navinreddyofficial/ Linkedin : https://in.linkedin.com/in/navinreddy20 TELUSKO Android App : https://go.telusko.com/TELUSKOAPP TELUSKO IOS App : https://apple.co/3SsgmU2 Discord : https://discord.gg/D8hWe9BqfF In this lecture we are discussing: 1)What is Access Modifiers ? Types of access Specifiers 2)How to use with example #1 What is Access Modifiers ? Types of access Specifiers -- Access Modifiers are keywords that determine the visibility and access level of a class, method, or data member. -- There are four types of access specifiers in Java: i) public: A public class, method, or data member is visible to all classes. ii) protected: A protected class, method, or data member can be accessed by classes within the same package, and any subclasses which extend the class. iii) default: A default class, method, or data member is visible only to classes within the same package. iv) private: A private class, method, or data member is only visible to the class it is declared in, and not to any subclasses. #2 package flder1.folder1; // import flder1.folder2.B; --The type flder1.folder2.B is not visible because class is not public import flder1.folder2.C; public class A { public static void main(String []args){ // B obj=new B(); --- we was not making class B as public --- so we get error C obj =new C(); //since, Class C is public so we can use outside the package of folder2 //for class visibility only public is legal modifiers has been used and if you not mention anything by default class is default. // System.out.println(obj.def); -- The field C.def is not visible because we want to access from different package but we have not visibility in current package because access specifier is default // System.out.println(obj.prot); not visible because access specifier is protected -- it is only visible in same package or visible in other package if class is subclass of that class. //protected visible to inherited class of different package also. Child ch =new Child(); // ch.a; -- not visible in anywhere. Since a is visible only in same class because it is private. } } class Child extends C{ private int a=9; public void natureProtected(){ System.out.println(prot); //here we can use protected variable becuase it is visible to inherited class in different package also } } /* step 1: create a folder flder1 Step 2: create two sub folder inside flder1 i) folder1 ii)folder2 step 3: create A.java file in folder1 step 4: create B.java, C.java in folder2 package flder1.folder2; class B { } package flder1.folder2; public class C { int def=5; protected int prot=6; public int pub=7; private int pvt=8; } */ Note : Remember visibility decrease in order public--protected--default(but this keyword not mentioned like public and private)--private Github repo : https://github.com/navinreddy20/Javacode.git More Learning : Java :- https://bit.ly/3x6rr0N Python :- https://bit.ly/3GRc7JX Django :- https://bit.ly/3MmoJK6 JavaScript :- https://bit.ly/3tiAlHo Node JS :- https://bit.ly/3GT4liq Rest Api :-https://bit.ly/3MjhZwt Servlet :- https://bit.ly/3Q7eA7k Spring Framework :- https://bit.ly/3xi7buh Design Patterns in Java :- https://bit.ly/3MocXiq Docker :- https://bit.ly/3xjWzLA Blockchain Tutorial :- https://bit.ly/3NSbOkc Corda Tutorial:- https://bit.ly/3thbUKa Hyperledger Fabric :- https://bit.ly/38RZCRB NoSQL Tutorial :- https://bit.ly/3aJpRuc Mysql Tutorial :- https://bit.ly/3thpr4L Data Structures using Java :- https://bit.ly/3MuJa7S Git Tutorial :- https://bit.ly/3NXyCPu Donation: PayPal Id : navinreddy20 https://www.telusko.com
You May Also Like
Unleash Creativity with These Slime Essentials
AI-recommended products based on this video

ESR for iPhone 16 Case, Military-Grade Protection, Shockproof Air Guard Corners, Yellowing-Resistant Acrylic Back, Phone Case for iPhone 16, Air Armor Series, New Clear Blue

Yarxiawin Phone Case for Samsung S25 Case with Ring Stand Magnetic Compatible with Magsafe Wireless Charger, Pink Bumper Cover Samsung Galaxy S25 Case Clear Shockproof (Blue)

Spigen Case for iPhone 16 Plus Case, Liquid Crystal Glitter Designed for Apple iPhone 16 Plus - Crystal Quartz

LITTLEFUN Decorate Your Own Baseball Cap with Glitter Gem Stickers for Kids Crafts Toys Gifts - Girls Birthday Presents

Jxngery Jxngery 4 Sets Graduation Stole with Gold Glitter Letter Good Decoration Simple Graduation Sashes Set for Home School Party

Furiet for Samsung Galaxy S24/S25 5G Floral Wallet Case with Flip Zipper Purse Wrist Strap Shoulder Strap Luxury Glitter PU Leather Card Holder Stand Phone Cover for S 24 24S 25 25S G5 Women Purple

GuaGua for Galaxy S25 Case Samsung S25 Case Glow in The Dark Noctilucent Luminous Cover Space Nebula Slim Thin Shockproof Protective Phone Cases for Samsung S25, Purple/Blue

LEGO Marvel Spider-Man's Car and Doc Ock Building Set, Spidey and His Amazing Friends Buildable Toy for Kids 4 Plus Years Old with Glow in The Dark Pieces, 10789

Kids Rock Painting Kit - Glow in The Dark - Arts & Crafts Easter Gifts for Boys and Girls Ages 4-12 - Craft Activities Kits - Creative Art Toys for 4, 5, 6, 7, 8, 9, 10, 11 & 12 Year Old Kids

Sukakimi Fort Building Kit, Glow In The Dark 155 Pcs Kids Fort Building Kit Construction Toys Diy Crazy Forts Indoor Outdoor For 4,5,6,7,8,9,10 Years Old Boys Girls

Floral Beads Kit 50000pcs & 300pcs Giant Large Colorful Gel Jelly Balls, Non Toxic Beads for Vase Filler, Plant, Floating Candles, Wedding and Home Decoration

Gifts 5-12 Years Old Girls, Bracelet Making Kit, Unicorn Toys, Gifts for Teen Girls, Beads for Making Jewellery, Crafts for Kids 6-8, Arts and Crafts for Kids Age 4 5 6 7 8 9 10 11

Hbnlai 5300 Pcs Clay Beads Bracelet Making Kit, Flat Preppy Beads for Friendship Jewelry Making, Polymer Heishi with Charms Gifts for Teen Girls Crafts for Girls Ages 8-12




















