🎮 એન્કેપ્સ્યુલેશન એડવેન્ચર
રમત દ્વારા ઑબ્જેક્ટ-ઓરિએન્ટેડ પ્રોગ્રામિંગ શીખો!
XP: 0/100
સ્તર:
શિખાઉ માણસ
સ્તર 1 - એન્કેપ્સ્યુલેશન શું છે
એન્કેપ્સ્યુલેશનનો અર્થ છે:
- વર્ગની અંદર ચલો અને પદ્ધતિઓનું બંડલિંગ.
- ચલોને ખાનગી બનાવીને ડેટાનું રક્ષણ કરવું.
- ગેટર્સ અને સેટર્સ તરીકે ઓળખાતી જાહેર પદ્ધતિઓ દ્વારા ડેટા ઍક્સેસ કરવો.
વર્ગ વિદ્યાર્થી{
ખાનગી શબ્દમાળા નામ;
જાહેર રદબાતલ સેટનામ(સ્ટ્રિંગ એન){
નામ=n;
}
સાર્વજનિક સ્ટ્રિંગ getName(){
પરત નામ;
}
}
ક્વિઝ 1
શા માટે પ્રોગ્રામરો એન્કેપ્સ્યુલેશનનો ઉપયોગ કરે છે
બધું જ જાહેર કરવા
To protect data and control access
To slow programs down
To protect data and control access
To slow programs down
Level 2 – Private Variables
Private variables cannot be accessed directly outside the class. Instead:
- Setter methods update them.
- Getter methods retrieve them.
private int age;
public void setAge(int a){
age=a;
}
public int getAge(){
return age;
}
Quiz 2
Which keyword hides variables?
public
private
static
private
static
Coding Challenge
Create a setter method called setName.
Final Boss Quiz
Encapsulation combines…
Variables and methods into one class
Loops and arrays
Internet connections
Loops and arrays
Internet connections
🏆 Congratulations!
You Mastered Encapsulation!
Enter your name:
