What is JAVA classes
A class is an entity that determines how an object will behave and what the object will contain. In other words, it is a blueprint or a set of instruction to build a specific type of object.
class <class_name>{ field; method; }
What is an Object?
An object is nothing but a self-contained component which consists of methods and properties to make a particular type of data useful. Object determines the behavior of the class. When you send a message to an object, you are asking the object to invoke or execute one of its methods.
From a programming point of view, an object can be a data structure, a variable or a function. It has a memory location allocated. The object is designed as class hierarchies.
Syntax
ClassName ReferenceVariable = new ClassName();
What is the Difference Between Object & Class?
A class is a blueprint or prototype that defines the variables and the methods (functions) common to all objects of a certain kind.
An object is a specimen of a class. Software objects are often used to model real-world objects you find in everyday life.
Example Code: Class and Object
class Student
{
int id;
String name;
}
class TestStudent
{
public static void main(String args[])
{
//Creating objects
Student s1=new Student();
//Initializing objects
s1.id=101;
s1.name=”Sonoo”;
//Printing data
System.out.println(s1.id+” “+s1.name);
}
}
No comments:
Post a Comment