How Do You Remember the 4 Concept of OOP in Java?
1 min readSep 20, 2020
When you start learning the OOP of Java, it could be complicate. Don’t be afraid. It is actuallys can be remembered by this way:
- Abstraction: When the program start, you are trying to get everything to the stage, but you don’t need to know the detail of each item. It provide simplicity for usage.
class Test {
public static void main(String[] args) {
Student s = new Student();
s.setName(“vijay”);
System.out.println(s.getName());
}
}
- Encapsulation: Then we are trying to describe each item. We need know what is inside (hiding detail), what is outside (public access).
public class Student {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name
}
}
- Inheritance: Same item we could reuse it again and again, we want to improve the reusability of the item, eg, newPhone extends oldPhone.
public class MasterStudent extends Student {
public void applyKnowlege() { ... }
}
- Polymorphism: while reusability is not enough, we involved more complex situation, that’s why polymorphism come through. Eg. we can have overridden method.
public class MasterStudent extends Student {
public void applyKnowlege(a) { ... }
public void applyKnowlege(a, b) { ... }
}