কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্টে প্যারেন্ট এবং চাইল্ড ক্লাসে একই নামের মেথড থাকতে পারে কিনা?


হ্যাঁ, প্যারেন্ট এবং চাইল্ড ক্লাসে একই নামের মেথড থাকতে পারে।

উদাহরণ

class Parent {    constructor(parentValue) {       this.parentValue = parentValue;    }    //Parent class method name which is same as Child Class method name.    showValues() {       console.log("The parent method is called.....");       console.log("the value is="+this.parentValue);    } } class Child extends Parent {    constructor(parentValue,childValue){       super(parentValue);       this.childValue = childValue;    }    //Child class method name which is same as Parent Class method name.    showValues() {       console.log("The child method is called.....");       console.log("The value is="+`${this.childValue}`);    } } var parentObject = new Parent(100); parentObject.showValues(); var childObject = new Child(400,500); childObject.showValues();

উপরোক্ত প্রোগ্রাম চালাতে নিচের কমান্ডটি ব্যবহার করুন −

node fileName.js.

এখানে, আমার ফাইলটির নাম demo195.js।

আউটপুট

এটি নিচের আউটপুট তৈরি করবে −

PS C:\Users\Amit\javascript-code> node demo195.js The parent method is called..... the value is=100 The child method is called..... The value is=500

  1. জাভাস্ক্রিপ্টে এরর নাম ভ্যালু উদাহরণসহ ব্যাখ্যা

  2. জাভাস্ক্রিপ্ট দিয়ে পেরেন্ট এলিমেন্টের চাইল্ড এলিমেন্ট পাওয়া

  3. জাভাস্ক্রিপ্টে একই অ্যারেতে অ্যারের এলিমেন্টগুলো ডুপ্লিকেট করা

  4. জাভাতে মেথডের নাম ক্লাসের নামের সাথে একই রাখা যাবে কি?