#40 Encapsulation 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 encapsulation?
2)how to achieve encapsulation
3)Benefits of encapsulation
4)how to use private data?

#1
What is encapsulation?
= binding data with method to make your program secure is known as encapsulation.
Consider encapsulation as we have capsule and inside capsule everything inside a class is wrapped or encapsulated.
e.g
class A{ private int a;
public void setA(int num){a=num;}
public int getA(){return a;}
}
//here you can see that we can bind data with method inside a curly braces, it seems look like a capsule inside everything is present.

#2
how to achieve encapsulation?
-- through access specifiers private,protected,public,default . We can achieve
encapsulation.

#3
Benefit of encapsulation
i)Helpful in to achieve abstraction
ii)for security point of view it is most beneficial.
iii)you can maintain log file through method when you bind your data with method.

#4
how to use private data?
-- using setters and getters method we can set and get the value of variable.
-- private int num;
public int getNum( )
{
return num;
}

public void setNum(int num)
{
}

Note:
Always make variable as private and method as public to achieve security in program.

More Learning :

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

I m experienced java developer .. i started watching this playlist to refresh but.. i ended up actually learning making me realize.. i dont know stuff still.However, I loved your teaching way.

prakrutijani
Автор

the way you explain this is magical. I went through videos to find out what encapsulation is and from you i found it. Highly Appreciated Man!

wolverine
Автор

Its 2 complete hrs, I'm still watching your playlist. Hats off Mr. Navin 👏

sakthipriya
Автор

Actually sir you're my favorite trainer 🔥

subajaelango
Автор

Sir your teaching skills are very good 💯 it's very helpful Java playlist for beginners thankyou so much and Allah bless you ✨👍

AyeshaKhan-ommu
Автор

00:04 Encapsulation is a part of object oriented programming.
01:33 Data is stored in the brain in the format of variables
02:57 Data access control in object-oriented programming
04:22 Private variables can only be accessed within the same class.
05:56 Data access is restricted using methods.
07:16 Private variables can only be accessed within the class that they are defined in.
08:51 Setting values for variables and accessing them using methods.
10:22 Encapsulation is a way to bind data and methods together

Mrindia-kn
Автор

the way you explain any topic is awesome, specially examples....

dr.renukapatel
Автор

Sir, you're tin god and one of my favourite and i like you, god will bless you helping a lot for who needs technical stack to grow their skill-set, hope you provide more content like this, finally your flow of explanation was outstanding, and i like you a lot and a lot more...🔥

yzubtbt
Автор

You are using examples from personal life; it’s good to let others learn things well. Try to give a minimum of two examples in each video per topic. Thanks.

LearnEnglishMM
Автор

there is no hesitation that you are the best trainer. you really understand how one should be taught it means you understand the problem a student face while studying and grasping the concept. love from the capital of india and from Bihar.

SoulOfBharat
Автор

You are superb sir💯💯💯the way of teaching is in easily understandable manner

jananisrivaideesh
Автор

You are Superb, the way you taught is excellent.

shortnews
Автор

you don't need to use a static block if you just want to initialze a field
private static String name = "Phone";
would be enough.
but if you need some complex manipulations, requires several lines of code, than yes, there static blocks come in

SB-pkss
Автор

your explination is awesome sir, easy to understand and grasp the concept.thank You🙏

subbu
Автор

this is absolutely understandable java concepts simply, thanku naveen sir

samnasaif
Автор

Sir your way of explaining is just brilliant!👏

aniketankush
Автор

@Telusko

I have a question sir,

We can even call the getAge() method by simply passing the value and calling it under Demo class, even age is private in class Human. I tried it and worked well, which states that we don't need setAge() method to set the value, can simply pass through the getAge() and fetch the value.

Please explain sir, how I am wrong and why do we need get, set methods here? I am pretty sure there must be point behind there :)

For eg:
public int getAge(int a)

{
age = a;
return a;
}

And while calling it under class demo, we can define:

Human obj = new Human();
int final = obj.getAge(56);

System.out.println(final);

xctgzie
Автор

you stored lot of information in your brain and by seeing itself everyoone can understand :) just kidding, lovely explanation

shaikbasha
Автор

Your teaching style is marvelous❤. Love from Nepal!

RGMUTEX
Автор

Explanantion was top notch! But my question is we use private access modifier so that other classes can't use it, and then we create get and set method through which we can change and access the value, if we are including get and set method for private variable, why we simply can't keep the vaiable public if in the end we need to access and change the data.

it.b..prashantsingh