classes in java for beginners | Tamil Explanation

Опубликовано: 04 Август 2026
на канале: siya_tech_tales
135
11

Follow us on Instagram: https://www.instagram.com/siyatechtal...
------------------------------------------------------------------
Think of a Java class as a blueprint for creating objects, just like a blueprint for a house.

Blueprint (Class): A house blueprint shows the design of the house, like the rooms, layout, etc. It defines what a house should look like and what it should contain but is not an actual house.

In Java, a class defines the properties (variables) and behaviors (methods) of objects but does not represent an actual object.

House (Object): You can build many houses from the same blueprint. Each house will have the same structure but can have different attributes (like color or furniture).

In Java, objects are instances of a class. You can create multiple objects from the same class, each with its own set of values for its properties.

Step-by-Step Example:
House Blueprint in Java
Define the Class (Blueprint)

Let’s create a House class. This will act as a blueprint, defining properties like color and numberOfRooms, and a method showInfo() to display details.

class House {
// Properties (Attributes)
String color;
int numberOfRooms;

// Constructor to initialize a house
House(String color, int numberOfRooms) {
this.color = color;
this.numberOfRooms = numberOfRooms;
}

// Method (Behavior)
void showInfo() {
System.out.println("House color: " + color);
System.out.println("Number of rooms: " + numberOfRooms);
}
}
Create Objects (Actual Houses)

Now, we can create specific houses using the House blueprint.

public class Main {
public static void main(String[] args) {
// Creating two House objects
House house1 = new House("Blue", 3);
House house2 = new House("Green", 4);

// Displaying information of each house
house1.showInfo();
house2.showInfo();
}
}

Output

When you run this code, you’ll get:

House color: Blue
Number of rooms: 3
House color: Green
Number of rooms: 4

Key Points for Beginners

Class: It’s a blueprint, not the actual object. Here, House is the class.

Properties: These are like features or characteristics of the object (e.g., color, numberOfRooms).

Methods: These are actions or behaviors that objects of the class can perform (e.g., showInfo()).

Object: An instance of the class with specific values for its properties, like house1 and house2.
----------------------------------------------------
Copyright Disclaimer under Section 52 of the Copyright Act, 1957 (India):
This video is made for educational, informational, and entertainment purposes only. The content is transformative in nature, and its use is considered fair use under Indian copyright law. No copyright infringement is intended, and all rights belong to their respective owners. The purpose of this video is to educate, inform, and entertain, and it is not intended to harm or exploit any individual or entity. If you have any concerns or objections, please contact us at [email protected]
-----------------------------------------------------
#java
#class
#javaprogramming