In every java programming language , A class can containing two types of Data Members .They are :
1.Non-static data members.
2.Static data member.
Instance Data Member
➢Instance data members memory space is created each every time whenever the object is created.
➢Instance data member are used for storing specific values which are suitable for individuals.
➢Instance data member declaration should not be preceded by 'Static keyword' .
Ex:- int a=10,20,30,40; (Instance Data Member)
➢Datatype V 1 ,V 2,V 3........V n ;.
➢Each & every instance data member must be access with respect to Object name
(Object . Instance Data Member Name)
➢Instance data member value are not shareable.
➢Instance data members are also called "Object level Data Members".Below following examples are the instance data type members.
EX : int student Id ;
String course;
String student name ;
float marks;
Static Data Members
➢ Static data members memory space is created once only when we defined the class then irrespective number of times objects are created.
➢ Static date members are used for storing common values which are suitable for all programmers.
➢ Static data members declaration is must be preceded by "static keyboard "
➢ Static" data type V 1,V 2.......V n ;
➢ Each & every data member must be access to respect to object even with class name (obj. class).
➢ Static data members are shareable
➢ Static data member are also called "class level data members ". Below following examples are the static data type members.
EX: static string course ;
static string Delhi ;
static string pi ;
NOTE:- Each every final variable must be static but a static variable value may are not be final .
static final float PI= 3.14f ;
static final String s="Java";
➠Each of instance method must be accessed with respect to object name.
{
Block of statements. Business logic
}
1.Non-static data members.
2.Static data member.
Instance Data Member
➢Instance data members memory space is created each every time whenever the object is created.
➢Instance data member are used for storing specific values which are suitable for individuals.
➢Instance data member declaration should not be preceded by 'Static keyword' .
Ex:- int a=10,20,30,40; (Instance Data Member)
➢Datatype V 1 ,V 2,V 3........V n ;.
➢Each & every instance data member must be access with respect to Object name
(Object . Instance Data Member Name)
➢Instance data member value are not shareable.
➢Instance data members are also called "Object level Data Members".Below following examples are the instance data type members.
EX : int student Id ;
String course;
String student name ;
float marks;
Static Data Members
➢ Static data members memory space is created once only when we defined the class then irrespective number of times objects are created.
➢ Static date members are used for storing common values which are suitable for all programmers.
➢ Static data members declaration is must be preceded by "static keyboard "
➢ Static" data type V 1,V 2.......V n ;
➢ Each & every data member must be access to respect to object even with class name (obj. class).
➢ Static data members are shareable
➢ Static data member are also called "class level data members ". Below following examples are the static data type members.
EX: static string course ;
static string Delhi ;
static string pi ;
NOTE:- Each every final variable must be static but a static variable value may are not be final .
static final float PI= 3.14f ;
static final String s="Java";
1) Instance / non-static methods
2) Static methods
Instance method
➠Instance methods are always recommended to use to perform "Repeated Operations" such as reading the records to files & reading the records from ' Data Base ' etc.
➠Instance methods are meant for performing specific operations which are suitable for individual programming.
➠Program-matically the definition of instance methods should not be presided by " Static keyword ".
➠Program-matically the definition of instance methods should not be presided by " Static keyword ".
Ex:- Return type method Name ( List of formal parameter if any)
{
Block of statement - Business logic
}
EX:- [Object name Instance Method name]
➠Instance methods results are not shareable because it performs specific operations.
➠Instance methods are also known as 'Object'
Ex:- Void callTotal( )
Ex:- Void callTotal( )
{
tot=m1+m2+m3;
}
tot=m1+m2+m3;
}
Static method
➠Static methods are recommended to perform one time operation such as opening a file, obtaining the data base collection.
➠Static methods are meant for performing common operation which are suitable for all programmers.
➠Static method is defined must be presided by "Static keyword".
Ex :- static Retype method name (list of formal parameter if any)
Block of statements. Business logic
}
➠Each & every static method must be access with respect to class name (even with object name). EX:- class name. static method name
➠static methods results are shareable because their performing common operations.
➠static methods are also known as class level methods.
EX:- public static void main (String args[])
{
s1 .calTotal( );
s2 .calTotal( );
}
No comments:
Post a Comment
Thanks for visiting my site..