0% found this document useful (0 votes)
48 views3 pages

Java Class Object Method

The document explains the concepts of class, object, and method in Java. A class serves as a blueprint for creating objects, while an object is an instance of a class created using the 'new' keyword. Methods are blocks of code within a class that perform specific tasks and can be invoked on objects.

Uploaded by

thenmozhi09l2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views3 pages

Java Class Object Method

The document explains the concepts of class, object, and method in Java. A class serves as a blueprint for creating objects, while an object is an instance of a class created using the 'new' keyword. Methods are blocks of code within a class that perform specific tasks and can be invoked on objects.

Uploaded by

thenmozhi09l2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java: Class, Object, and Method

1. Class in Java

A class is a blueprint or template for creating objects. It defines attributes (fields) and behaviors (methods).

Syntax:

class ClassName {

// Fields

int x;

// Methods

void sayHello() {

[Link]("Hello!");

2. Object in Java

An object is an instance of a class. You create an object using the `new` keyword.

Syntax:

ClassName obj = new ClassName();

3. Method in Java

A method is a block of code that performs a specific task. It belongs to a class and can be called on an

object.
Java: Class, Object, and Method

Syntax:

returnType methodName(parameters) {

// code

Example:

class Car {

String color;

int speed;

void drive() {

[Link]("The car is driving at " + speed + " km/h.");

void setDetails(String c, int s) {

color = c;

speed = s;

void showInfo() {

[Link]("Color: " + color);

[Link]("Speed: " + speed);

}
Java: Class, Object, and Method

public class Main {

public static void main(String[] args) {

Car myCar = new Car();

[Link]("Red", 100);

[Link]();

[Link]();

Output:

Color: Red

Speed: 100

The car is driving at 100 km/h.

Summary

Class: Blueprint that defines objects

Object: Instance of a class

Method: Function defined inside a class

You might also like