We Offer 100% Job Guarantee Courses (Any Degree / Diploma Candidates / Year GAP / Non-IT / Any Passed Outs). Placement Records
Hire Talent (HR):+91-9707 240 250

General

Class and Object in Java

Class and Object in Java

Class and Object in Java

What is Class?

A class is a basic run-time entity and it contain collection of  properties and methods.

Syntax:

[message type=”simple” bg_color=”#eeeeee” color=”#333333″]
Class Class-name
{
//Data member and member functions
}
[/message]

Example:

[message type=”simple” bg_color=”#eeeeee” color=”#333333″]
Class Add
{
Public Int num1,num2; //data member
Public int addition(int a,int b)// member function
}
[/message]

What is Object?

Instance of a class is called as Object. It is used to access the data member and member functions of class.

Creating object of class:

Syntax:

Classname obj-name=new classname();

Example:

Add a=new Add();

Accessing data member

Obj-name.VariableName;

Example:

a.num1
a.num2

Accessing member function

Obj-name.MethodName;

Example:

addition(23,45);

Click Here-> Get Java Training with Real-time Projects

Besant Technologies WhatsApp