Data Binding: salary is an instance variable and should be accessed with an object only, through static main() method. Two objects o1 and o2 are created and salary field is called. The object o1 gets a salary of 5000 and o2 gets 6000. If an instance variable is called with an object, a location is created in the memory. Now two locations are created in the memory for o1.salary and o2.salary. That is, one location of salary is binded with o1 and another location of salary is binded with o2. This is is known as data binding.
Data Hiding:- Due to this binding habit, the salary location of o1 is hidden from o2 and similarly the salary location of o2 is hidden from o1. This is known as data hiding.
Encapsulation:- Due to hiding, o1 cannot access o2 salary and o2 cannot access o1 salary. That is, the variable salary is encapsulated with object o1 and becomes one unit of data. Similarly another unit o2 is made with its own salary, entirely separate from o1 unit. This is known as encapsulation.
Encapsulation is a pharmaceutical term where drug powder is placed in a capsule to hide its properties, like taste and color etc., from the patients. Due to data hiding, the properties (the value of fields(instance variables)) of an object are hidden from other objects. This exactly resembles a capsule.
Advantage:- encapsulation is one instance variable can be given multiple values, of course, by calling with different objects.
Program to swap two numbers without using third variable:
Suppose a=10 and b=20
Then logic will be
1) a=a+b
b=a-b
a=a-b
a=10+20=30
b=30-20=10
a=30-10=20
Now, a=20 and b=10
2) a=a*b
b=a/b
a=a/b
a=10*20=200
b=200/20=10
a=200/10=20
So,a=20 and b=10
You can use any of the above logic in your program.
Suppose a=10 and b=20
Then logic will be
1) a=a+b
b=a-b
a=a-b
a=10+20=30
b=30-20=10
a=30-10=20
Now, a=20 and b=10
2) a=a*b
b=a/b
a=a/b
a=10*20=200
b=200/20=10
a=200/10=20
So,a=20 and b=10
You can use any of the above logic in your program.
👍1
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
29.7 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
27.6 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
15.1 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
24.8 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
12.3 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
9.7 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
15.9 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
19.1 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
18.6 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
33 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
33.6 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
21.4 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
29 MB
Forwarded from Advanced JAVA
Copy_of_Object_Oriented_Analysis_Design_Track_Practice_GeeksforGeeks.ts
23.9 MB