Java Tính đa hình
Giới Thiệu Polymorphism
Polymorphism là gì?
Compile-time Polymorphism
Cú pháp Method Overloading
class MathOperation {
int add(int a, int b) {
return a + b;
}
double add(double a, double b) {
return a + b;
}
int add(int a, int b, int c) {
return a + b + c;
}
}Ví dụ minh họa Method Overloading
Runtime Polymorphism
Cú pháp Method Overriding
Ví dụ minh họa Method Overriding
Lợi ích của Polymorphism
Ví dụ minh họa
Bài tập thực hành
Bài tập 1: Method Overloading
Bài tập 2: Method Overriding
Bài tập 3: Polymorphism với kế thừa
Last updated