Difference Between Class and Object:
1.Class : Class is a container which collection of variables and methods.
Object:::object is a instance of class
2.Class:::: No memory is allocated at the time of declaration
Object:::Sufficient memory space will be allocated for all the variables of class at the time of declaration.
3.Class:::One class definition should exist only once in the program.
Object:::::Object:For one class multiple objects can be created
Syntax of Class:
class Class_Name
{
data member;
method;
}
Example of Object And Class::
class Student
{
int studentid; // data member (or instance variable)
String studentname; // data member (or instance variable)
studentid=1;
studentname="vidyarthi";
public static void main(String args[])
{
student std=new student(); // Creating an object of class Employee
System.out.println("Student ID: "+std.studentid);
System.out.println("Student Name: "+std.studentname);
}
}
Note: A new keyword is used to allocate memory at runtime, new keyword is used for create an object of class, later we discuss all the way for create an object of class.
1.Class : Class is a container which collection of variables and methods.
Object:::object is a instance of class
2.Class:::: No memory is allocated at the time of declaration
Object:::Sufficient memory space will be allocated for all the variables of class at the time of declaration.
3.Class:::One class definition should exist only once in the program.
Object:::::Object:For one class multiple objects can be created
Syntax of Class:
class Class_Name
{
data member;
method;
}
Example of Object And Class::
class Student
{
int studentid; // data member (or instance variable)
String studentname; // data member (or instance variable)
studentid=1;
studentname="vidyarthi";
public static void main(String args[])
{
student std=new student(); // Creating an object of class Employee
System.out.println("Student ID: "+std.studentid);
System.out.println("Student Name: "+std.studentname);
}
}
Note: A new keyword is used to allocate memory at runtime, new keyword is used for create an object of class, later we discuss all the way for create an object of class.
0 comments:
Post a Comment