Encapsulation Inhetance and Polymorphism
Encapsulation Inhetance and Polymorphism
PR O G R A M M IN
G
Let’s have some recap!
DIRECTION: Reveal the word by analyzing the given set of pictures and letters.
CLUE: KINDS OF MATERIALS INSERTING IN MICROSOFT
WORD
And mean.
Definition of variable.
Identify the different types of variables.
Declaring(creates)variables.
ENCA P SU LAT I O N
What is access modifier?
The meaning of Encapsulation, is to make sure that
"sensitive" data is hidden from users. To achieve this, you
must:
// Getter
public String getName() {
return name;
}
// Setter
public void setName(String newName) {
this.name = newName;
}
}
Explained
The get method returns the value of the variable name.
class Main {
public static void main(String[] args) {
Animal myAnimal = new Animal(); // Create a Animal
object
Animal myPig = new Pig(); // Create a Pig object
Animal myDog = new Dog(); // Create a Dog object
myAnimal.animalSound();
myPig.animalSound();
myDog.animalSound();
}
Output
The animal makes a sound
The pig says: wee wee
The dog says: bow wow