Java စူပါ သော့ချက်စာလုံး
ဥပမာ
(subclass) super
၏ superclass ကိုခေါ်ဆိုရန် အသုံးပြုခြင်း -Dog
class Animal { // Superclass (parent)
public void animalSound() {
System.out.println("The animal makes a sound");
}
}
class Dog extends Animal { // Subclass (child)
public void animalSound() {
super.animalSound(); // Call the superclass method
System.out.println("The dog says: bow wow");
}
}
public class Main {
public static void main(String args[]) {
Animal myDog = new Dog(); // Create a Dog object
myDog.animalSound(); // Call the method on the Dog object
}
}
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
super
သော့ချက်စကားလုံးသည် superclass (မိဘ) အရာဝတ္ထုများကို ရည်ညွှန်းသည် ။
၎င်းကို superclass နည်းလမ်းများကိုခေါ်ဆိုရန်နှင့် superclass constructor ကိုဝင်ရောက်ရန်အသုံးပြုသည်။
သော့ချက်စကားလုံး၏ အသုံးအများဆုံးအသုံးပြုမှုမှာ super
အမည်တူနည်းလမ်းများရှိသည့် superclass နှင့် subclass များအကြား ရှုပ်ထွေးမှုများကို ဖယ်ရှားရန်ဖြစ်သည်။
သော့ချက်စကားလုံးကို နားလည် ရန်၊ Inheritance နှင့် Polymorphismsuper
တို့ကို အခြေခံနားလည်ထားသင့်သည် ။
ဆက်စပ်စာမျက်နှာများ
ကျွန်ုပ်တို့၏ Java Inheritance Tutorial တွင် အမွေဆက်ခံခြင်း (အတန်းခွဲများနှင့် စူပါအတန်းအစားများ) အကြောင်း ပိုမိုဖတ်ရှုပါ ။
ကျွန်ုပ်တို့၏ Java Polymorphism Tutorial တွင် polymorphism အကြောင်းပိုမိုဖတ်ရှုပါ ။