Java Methods — தமிழ்

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

Java Methods

Give a reusable action a name.

Step-by-step explanationsRunnable JavaPractice + answer

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

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

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

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

A method groups an operation behind a clear name. Separate its inputs, its returned value, and any side effects such as printing. A small method is easier to test when its result depends on explicit parameters.

02 / Step by step

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

Methods-ஐ எப்படி பயன்படுத்துவது?

Method என்பது ஒரு குறிப்பிட்ட task-ஐ பண்றதுக்கான code block — only when called ஆகும்போது மட்டுமே run ஆகும்.

Method declare பண்றதுக்கு:

  • Method பேர் வை
  • Parentheses () போடு
  • Curly braces-க்கு {} உள்ளே code எழுது

Method Call பண்றது

Method-ஐ use பண்றதுக்கு அதோட பேரை call பண்றோம்:

Static vs. Public Methods

static method — object create பண்ணாமலே call பண்ணலாம்.
public method — object create பண்ணி call பண்ணணும்.

Java reference fragmentJAVA
static int multiply(int a, int b) {
    return a * b;
}

static void greet(String name) {
    System.out.println("Hello, " + name + "!");
}

System.out.println(multiply(4, 7));  // 28
greet("Alice");                       // Hello, Alice!

// Overloading
static double multiply(double a, double b) { return a * b; }
System.out.println(multiply(2.5, 4.0));  // 10.0

Java-வில் method overriding-க்கும் method overloading-க்கும் என்ன வித்தியாசம்?

  1. வித்தியாசமே இல்லை
  2. Overloading — same name, different parameters. Overriding — subclass-ல் parent method-ஐ redefine செய்வது
  3. Overriding — compile time. Overloading — runtime
  4. Overloading only for constructors
Reveal answer / விடை

Overloading — same name, different parameters. Overriding — subclass-ல் parent method-ஐ redefine செய்வது

Overloading: same method name, different parameter types/count (compile-time). Overriding: subclass-ல் parent class method-ஐ new implementation-உடன் redefine செய்வது (runtime polymorphism).

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 {
    static int square(int n) { return n * n; }
    public static void main(String[] args) { System.out.println(square(5)); }
}
Predict first. Then reveal the expected output / வெளியீடு
25

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

Call square with 0, -3, and 6.

Reveal the answer and reasoning / விடை

The results are 0, 9, and 36. The return value is computed from the supplied argument.

தவிர்க்க வேண்டிய தவறு: A non-void method must return an appropriate value along every reachable path that completes normally.

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

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