Java Class Attributes — தமிழ்

</>Coding Tamilan.← Java course & curriculum
Java Masterclass · Lesson 26 / 50 · தமிழ்

Java Class Attributes

Describe the state of each object.

Step-by-step explanationsRunnable JavaPractice + answer

முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.

இந்தப் பாடத்தில்…

  • Explain the key idea behind Class Attributes.
  • Read and run a complete example, then predict what changes.
  • Recognize the topic-specific mistake discussed below.
01 / The concept

அடிப்படையைப் புரிந்துகொள்ளுங்கள்

Fields store object or class state. An instance field belongs to each object; a static field is associated with the class. Give fields sensible defaults and avoid exposing every field publicly in real application models.

02 / Step by step

விரிவான விளக்கங்கள்

Java Class Attributes

Class attributes என்பது class-க்கு உள்ளே இருக்குற variables — fields என்றும் சொல்வோம்.

Attribute values-ஐ access பண்ண dot (.) syntax use பண்றோம்:

Attributes Modify பண்றது

Attribute value-ஐ மாத்துவது:

final Attributes

Attribute மாறவே கூடாதுன்னா final பயன்படுத்தலாம்:

Final Fields (Constants)

Java reference fragmentJAVA
class Circle {
    final double PI = 3.14159;  // constant
    double radius;

    double area() { return PI * radius * radius; }
}

Circle c = new Circle();
c.radius = 5;
System.out.println(c.area());  // 78.53975
// c.PI = 3.0;  // ERROR: cannot assign to final variable

Java-வில் `static` variable என்றால் என்ன?

  1. ஒரு object-க்கு மட்டும் சொந்தமானது
  2. Class-க்கே சொந்தமானது — எல்லா objects-உம் share செய்யும்
  3. Constant variable
  4. Private variable
Reveal answer / விடை

Class-க்கே சொந்தமானது — எல்லா objects-உம் share செய்யும்

`static` variables class-level-ல் இருக்கும் — எல்லா instances-உம் ஒரே value share செய்யும். Example: `Student.count` — எத்தனை students create ஆனார்கள் என்று track செய்ய.

03 / Read and predict

முழுமையான உதாரணம்

This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.

Main.java · complete runnable exampleJAVA
public class Main {
    public static void main(String[] args) throws Exception {
        Lamp desk = new Lamp();
        Lamp floor = new Lamp();
        desk.on = true;
        System.out.println(desk.on);
        System.out.println(floor.on);
    }
}
class Lamp { boolean on; }
Predict first. Then reveal the expected output / வெளியீடு
true
false

The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.

04 / Learn by changing

Change it. Run it. Understand it.

Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.

Open Java editor ↗
After the editor loads, choose Load this lesson example, then press RUN.

Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.

05 / Your turn

நீங்களே முயற்சி செய்யுங்கள்

Practice challenge

Set floor.on to true and print both values again.

Reveal the answer and reasoning / விடை

Both print true because you explicitly changed the second object as well.

தவிர்க்க வேண்டிய தவறு: An uninitialized boolean instance field defaults to false, but an uninitialized local variable cannot simply be read.

பாடத்தின் சுருக்கம்

  • Explain the example without reading the output first.
  • Make the change requested in the practice task.
  • Describe why the result changed—or why compilation failed.

Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.

Coding Tamilan · Understand the idea. Try the code. Build the habit.