Java Classes/Objects — தமிழ்

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

Java Classes/Objects

Use one blueprint to create independent objects.

Step-by-step explanationsRunnable JavaPractice + answer

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

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

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

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

new creates an object and returns a reference. Variables can point to separate objects or to the same object. Distinguishing an object from a reference helps explain why assigning one reference to another can share mutable state.

02 / Step by step

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

Java Classes மற்றும் Objects

Java ஒரு object-oriented language — எல்லாமே classes மற்றும் objects-ஐ சுத்தி revolve ஆகும்.

Class என்பது object-களுக்கான blueprint. Object என்பது class-ஓட instance.

Class Create பண்றது

class keyword use பண்ணி class create பண்றோம்:

Object Create பண்றது

Class-ல இருந்து object create பண்றதுக்கு new keyword use பண்றோம்:

ஒரு class-ல இருந்து எத்தனை objects வேணும்னாலும் create பண்ணலாம். ஒவ்வொரு object-உம் அதன் சொந்த attributes values வையுங்கள்க்கலாம்.

Java reference fragmentJAVA
class Dog {
    String breed;
    int age;

    void bark() {
        System.out.println(breed + " says: Woof!");
    }
}

Dog d = new Dog();
d.breed = "Labrador";
d.age = 3;
System.out.println(d.breed + ", age " + d.age);  // Labrador, age 3
d.bark();   // Labrador says: Woof!

Java-வில் object create செய்ய எந்த keyword பயன்படுத்துவோம்?

  1. create
  2. object
  3. new
  4. make
Reveal answer / விடை

new

`new` keyword heap memory-ல் object create செய்து constructor-ஐ call செய்யும். Example: `Car myCar = new Car();` — Java 16+ Records-ல் data classes-க்கு boilerplate குறைக்கலாம்.

Java Records (Java 16+): Data-only classes-க்கு boilerplate குறைக்க Java 16 Records வந்தது. record Point(int x, int y) {} — ஒரே line-ல் constructor, getters, equals(), hashCode(), toString() எல்லாம் automatic-ஆக கிடைக்கும். DTOs மற்றும் value objects-க்கு மிக ideal.

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 {
        Book first = new Book();
        Book second = new Book();
        first.title = "Java Basics";
        second.title = "Java Practice";
        System.out.println(first.title);
        System.out.println(second.title);
    }
}
class Book { String title; }
Predict first. Then reveal the expected output / வெளியீடு
Java Basics
Java Practice

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

Replace second = new Book() with second = first, then change second.title.

Reveal the answer and reasoning / விடை

Both references now point to the same Book, so reading first.title sees the change made through second.

தவிர்க்க வேண்டிய தவறு: Assigning an object reference does not clone the object.

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

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