Lesson 26 of 34

Constructors, this

9 min 30 XP

Constructor എന്നത് class-ന്റെ പേരുള്ള, return type ഇല്ലാത്ത ഒരു പ്രത്യേക method ആണ്. new-ൽ അത് സ്വയം പ്രവർത്തിക്കുന്നു. this.name എന്നാൽ object-ന്റെ field; വെറും name എന്നാൽ parameter.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

toString() override ചെയ്താൽ System.out.println(object) Book@1b6d3586-ന് പകരം വായിക്കാവുന്ന ഒന്ന് print ചെയ്യും.

Challenge

+30 XP

name, salary fields, constructor Employee(String name, int salary), method int annualSalary() (salary × 12) എന്നിവയുള്ള class Employee എഴുതൂ. main()-ൽ name, salary വായിച്ച് print ചെയ്യൂ: Input: Ravi 25000 Output: Ravi earns 300000 per year

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.