Java Class Methods — தமிழ்

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

Java Class Methods

Ask an object to do something.

Step-by-step explanationsRunnable JavaPractice + answer

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

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

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

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

Instance methods operate in the context of an object and can read its fields. Static methods have no implicit current object. Put behavior with the state it acts on, and choose static for operations that do not need instance state.

02 / Step by step

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

Java Class Methods

Methods-ஐ class-க்கு உள்ளே declare பண்றோம் — object அல்லது class-ஐ use பண்ணி call பண்ணலாம்.

static methods object இல்லாமலே call ஆகும். public methods object-ஐ use பண்ணி call பண்றோம்:

Static vs Instance Methods

Java reference fragmentJAVA
class MathHelper {
    static int square(int n) { return n * n; }  // Static
}
class Car {
    String brand;
    void describe() { System.out.println("I am a " + brand); } // Instance
}

System.out.println(MathHelper.square(4));  // 16 — no object
Car c = new Car();
c.brand = "Toyota";
c.describe();  // I am a Toyota
FeatureStatic MethodInstance Method
Called onClass name: MathHelper.square()Object: c.describe()
Access attributes?No (no this)Yes (has this)
Keywordstatic(no keyword needed)
Best forUtility / helper logicObject behaviour

`static` method-ஐ எப்படி call செய்வோம்?

  1. Object create செய்து call செய்வோம்
  2. ClassName.methodName() என்று directly call செய்வோம்
  3. super.methodName() என்று call செய்வோம்
  4. this.methodName() என்று call செய்வோம்
Reveal answer / விடை

ClassName.methodName() என்று directly call செய்வோம்

`static` methods class-க்கே சொந்தம். Object create செய்யாமல் `Math.sqrt()`, `Arrays.sort()` போல் ClassName.method() என்று call செய்யலாம்.

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 {
        Greeter greeter = new Greeter();
        greeter.name = "Kavi";
        greeter.greet();
        System.out.println(Greeter.doubleValue(6));
    }
}
class Greeter {
    String name;
    void greet() { System.out.println("Hello, " + name); }
    static int doubleValue(int n) { return n * 2; }
}
Predict first. Then reveal the expected output / வெளியீடு
Hello, Kavi
12

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

Create a second greeter with another name and call greet on it.

Reveal the answer and reasoning / விடை

Each call uses the name stored in the object on which greet is invoked.

தவிர்க்க வேண்டிய தவறு: A static method cannot directly use an instance field without an object reference.

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

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