Lesson 26 of 34

Constructors மற்றும் this

9 min 30 XP

Constructor என்பது class-ன் பெயரிலேயே உள்ள சிறப்பு method, return type இல்லை. 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) அழகான text-ஐக் காட்டும்.

Challenge

+30 XP

Employee class: fields name, salary; constructor Employee(String name, int salary); method int annualSalary() (salary × 12). 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.