Lesson 25 of 34

Classes மற்றும் ObjectsClasses and Objects

10 min 30 XP

Java ஒரு object-oriented மொழி. Class ஒரு வரைபடம் (blueprint): அதில் fields (தரவு) மற்றும் methods (செயல்கள்) இருக்கும். new மூலம் அந்த class-லிருந்து objects உருவாக்குகிறோம். ஒவ்வொரு object-க்கும் தனி மதிப்புகள்.

Java is object-oriented. A class is a blueprint with fields (data) and methods (actions). We create objects from it with new, and each object has its own values.

Example: edit me and press Run

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

ஒரு file-ல் ஒரே ஒரு public class மட்டும் இருக்கலாம். மற்ற classes-ஐ public இல்லாமல் Main-க்கு மேலே எழுதுங்கள்.

A file can have only one public class. Write your other classes above Main without the word public.

Challenge

+30 XP

Rectangle என்ற class எழுதுங்கள்: fields length, width; methods area() மற்றும் perimeter(). main()-ல் length, width படித்து இப்படி print செய்யுங்கள்: Input: 5 3 Output: Area: 15 Perimeter: 16

Write a class Rectangle with fields length and width and methods area() and perimeter(). In main(), read length and width and print: Input: 5 3 Output: Area: 15 Perimeter: 16

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