Java Modifiers — தமிழ்

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

Java Modifiers

Make ownership and access intentional.

Step-by-step explanationsRunnable JavaPractice + answer

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

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

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

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

Modifiers answer different questions. public/private affect access; static affects class versus instance membership; final prevents reassignment of a variable. A final object reference does not make the referenced object deeply immutable.

02 / Step by step

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

Java Modifiers என்னன்னு தெரியுமா?

Modifiers என்பது classes, methods, attributes-ஓட access-ஐ control பண்றதுக்கு use ஆகுது.

Access Modifiers

Modifierவிளக்கம்
publicஎல்லாரும் access பண்ணலாம்
privateஅந்த class-ல மட்டுமே access பண்ணலாம்
protectedஅதே package அல்லது subclass-ல access பண்ணலாம்
(default)அதே package-ல மட்டுமே access பண்ணலாம்

Non-Access Modifiers

  • final — class inherit ஆகாது, method override ஆகாது, variable மாறாது
  • static — class-க்கு சொந்தமானது, object-க்கு இல்ல
  • abstract — abstract class அல்லது method-க்கு

Non-Access Modifiers

ModifierApplies toEffect
staticFields, methodsBelongs to the class, not an instance
finalClasses, methods, variablesCannot be extended, overridden, or changed
abstractClasses, methodsNo body — must be implemented by a subclass
synchronizedMethods, blocksThread-safe — only one thread at a time
transientFieldsSkipped during object serialization
volatileFieldsAlways read from main memory — safe across threads
Java reference fragmentJAVA
// static — shared by all instances
class Counter {
    static int count = 0;
    Counter() { count++; }
}

// final — cannot change
final double PI = 3.14159;
// PI = 3.0;  // ERROR

// abstract — must override
abstract class Shape {
    abstract double area();
}
class Square extends Shape {
    double side;
    double area() { return side * side; }
}

`private` access modifier என்ன செய்யும்?

  1. எல்லா classes-லும் access கொடுக்கும்
  2. Same package-ல் மட்டும் access கொடுக்கும்
  3. அந்த class-க்குள் மட்டும் access கொடுக்கும்
  4. Subclasses-க்கு access கொடுக்கும்
Reveal answer / விடை

அந்த class-க்குள் மட்டும் access கொடுக்கும்

`private` — most restrictive. அந்த class-க்குள் மட்டுமே access. Encapsulation implement செய்ய இதை use செய்வோம். Getter/setter methods மூலம் controlled access கொடுக்கலாம்.

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 {
        System.out.println(Settings.LANGUAGE);
        System.out.println(Settings.doubleValue(4));
    }
}
class Settings {
    static final String LANGUAGE = "Java";
    static int doubleValue(int n) { return n * 2; }
}
Predict first. Then reveal the expected output / வெளியீடு
Java
8

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

Try reassigning Settings.LANGUAGE, then undo that change.

Reveal the answer and reasoning / விடை

The assignment fails to compile because the field is final.

தவிர்க்க வேண்டிய தவறு: static and public are different concepts: being static does not make a member accessible everywhere.

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

  • 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.