Don't let the Lockdown slow you Down - Enroll Now and Get 3 Course at 24,999/- Only. Explore Now!

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

Scroll Up
Besant Technologies WhatsApp