🎮 캡슐화 모험
객체지향 프로그래밍을 게임으로 배워보세요!
XP: 0/100
수준:
초보자
레벨 1 – 캡슐화란 무엇입니까?
캡슐화는 다음을 의미합니다.
- 클래스 내에서 변수와 메소드를 함께 묶습니다.
- 변수를 비공개로 설정하여 데이터를 보호합니다.
- Accessing data through public methods called getters and setters.
class Student{
private String name;
public void setName(String n){
name=n;
}
public String getName(){
return name;
}
}
Quiz 1
Why do programmers use encapsulation?
To make everything public
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:
