#54 Access Modifiers in Java

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

For More Queries WhatsApp or Call on : +919008963671

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

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.

//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(){
}
}

/*
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

class B {
}
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

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

Continuing same example for every video is little bit confusing so that we have to watch 12 hours video

qzuxgbu
Автор

Great video, thank you!
I think it would be more accessible if you had stuck to the same example but only switching the modifiers.

Cablur
Автор

Nice explanation. The table helped a lot

MykytaStr
Автор

Thank you for keeping it so simple! Watched a few other videos and was confused this was great!

sidiqmoltafet
Автор

The presentation of the folder package is not clear. Why are you keep rushing. Not suitable for beginners. Only guys who knows Java already can understand

boopathirajagopalan
Автор

sir, package line is note coming when i move a file to a folder

madhumukkera
Автор

default- can be accesed in same package
cant have 2 public class in same file

attrey
Автор

Sir please explain about

Void and return

jyotidhananjay
Автор

How it Will Compile When .java Files are in Different Folder

bcqfmem
Автор

sir, tell the extention you are using

madhumukkera
Автор

Good Evening Sir
Sir I have interview on java so can u help me sir so that i can crack it easily

AnjaliYadav-exkw
Автор

Please speak clear and little bit slow

AmitMishra_