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.