Class and objects in Java.

In this article,Class and objects in Java are explained in detail, we will come to know about the Class and objects in java,What is are the definitions of object,state,class,behaviour,identity,use of object in java program.
Object
Object is a physical product representing a particular class and is used by end-customer.
Ex
  • A physically constructed house by an Engineer which is ready to occupy in an Object.
  • Maruti Suzuki alto 800 AC car.
  • A Hyundai grand i10 sportz model car.   (From topic Class and objects in Java)
Definition
Object is an instance of a class,that represents state and behaviour of a class at a particular situation of type.
SYNTAX:
classname object-name;
(object-name)=new class-name();
Ex: student s1; //object declaration.
       s1=newstudent(); // object creation or instantiation.
Object name is an Identifier in a program. new is a operator in java, using which we create an object of a particular class.Once object is created, memory is allocated for that object in JVM/RAM.
Ex: student s2=new student(); //object-initialization.
During declaration, if object is created then it is known as object-initialization.
Ex:student s3,s4; //multiple object declarations.
Note: In the above s1,s2,s3,s4 represents one individual student record/data.
* Object is a variable of type class, hence class is a composite datatype i.e, based on primitive data types.
Every object has 3 characters they are:        (From topic Class and objects in Java)

State represents property/data members of a class.
Behaviour represents functionality/activities of a class.
Identity represents unique name of an object. (From topic Class and objects in Java)

How to use object in a program         
Object-name is used to access data-members or methods of a class using .(dot) operator.
Ex
s1.rollno=1001;
s1.sname="sai";
s1.age=21;
alternatively,we can also use object,to access methods of a class.
s1.attendsession();
s1.writeexam();

Class and objects in java-javaform

Output
student details are:
Roll no is 1001
Name is vijay
Age is 21


Java Class
General definition of class         (From topic Class and objects in Java)
A class is a model/prototype/design of a product,which is supposed to be developed/manufactured as end product to the customer.
Ex:
1. The blueprint of a house is designed by civil engineer before construction of a house.
2.The design/architecture of a car is done by automobile engineer, before it is manufactured in a factory. (From topic Class and objects in Java)

Definition of class(Java Programing)
A class groups together or is a collection of data and functionality of a entity.
Data+functionality=class
A class is nothing but an encapsulated unit which is a feature of OOPS. i.e.encapsulation.

Defining a class
Class is a keyword using which we declare or define it in a program.
1.class<<class Number>>[extends<<base class>>]
{
data-members;             (From topic Class and objects in Java)
-------
-----
methods;//here methods means functions
-------
------
}

2.class <class_name>
{  
    data member;  
    method;  
}  

Data-members are also known as properties, specifications, attributes, dimensions,data items of a class.
Methods are also known as functions,procedures,activities,routines,working mechanism,actions of a class.
Example of a class
Class name is an identifier.It obeys all the six rules of Identifiers.
Note:Class is a best example for Encapsulation. (From topic Class and objects in Java)
Class student
{
    
int roll no;        |
String Sname;  |------>>Data-members.
int age;             |
void attend section()  |
{------                         |
------                           |-------->> Methods.
}                                 |
Void write exam()      |
{----
-----
}
}


Continue to next topic Methods in Java

Begin your career in Digital Marketing,What is digital marketing? Digital Marketing online course. It's an current evolving technology which can give support to establish your own startup through Digital Marketing.

Do check my new startup Surprise Planners in HyderabadLavish Surprises our services are surprise party planners in Hyderabad, surprise giftssurprise birthday party planners Hyderabad, Wedding anniversary surprises,surprise planners Hyderabad.

Hi Friends, Please comment down your views in the comment section below. Thank you...

No comments:

Connect with Us by Subscribing here for more Updates..!

* indicates required