Java4teachus

Wednesday, December 05, 2018

Definition Of Object & Create an Object in Java

Create an Object 

  • We know that when we define a class memory space is not created so that data members and method but whose memory is created when we create an  "Object".
  • In other word to enter for the data member of a class, first we must allocate memory space for data member by creating an"Object" .
  • To do any data processing we must create an "Object".
  • To create an object either must exist a class definition otherwise it is compile error.
Definition of object
  • Instance of a class is called an"Object" ( instance is nothing but allocating sufficient amount of memory space for "Data members & Method" ).
  • Each & every class variable is called an "Object".
  • Each & every grouped item is called "Object".  
  • (in grouped item is a variable which allows to store multiple value of same type or different type or both types.)
Creating an object in java
  • Creating an object in nothing but allocating the sufficient amount of memory space for data members and methods of a class. By following dynamic memory allocation with the help of new operator and it is called "dynamic memory allocation" operator.

New Operator In Java 

  • It  allocates  sufficient  amount of memory space for data member and method of specified  class.  
  • It takes an address / reference of created memory space and placing it into L.H.S variable i.e.   is  object  name.
  • Out  of  many  way  of creating an object in java with 'New Operator' .
  • We can create an object with two syntax's  they are:

Syntax:-1

<Class name>  <object> = new  <Class name > ----> 1

➽ create an object of Student class.
       
     Student  S= new Student( );


➽ Create an object of Circle class.

     Circle   C= new Circle( );

➽ Create an object of Employee Class.

     Employee e = new Employee( );


From the above examples we create an object by using the Class name called Employee or Programmer defined data type.

Here Employee is the 'programmer defined datatype' and 'e' is one of the 'reference variable or object' of Employee class. In Java by default reference variable contain 'Hash code / Hexa decimal code' which is very high security for applications.



Syntax:- 2 

<class name>  <obj> ; → Statement 1

<obj> = new <class name( )>; → Statement 2

Explanation :  

Statement 1  represent  “Object declaration”,when an  object  is declared the Memory space is not created data member and methods by default value of declared  object is “null".

EX:    Student        S ;               null
           Circle            C ;               null
           Rectangle    R;                null
           String   name ;                null

➠ Statement represents "Object referring". when object is reference memory space is create for data member & method and default value of reference is not null it is nothing but "Hash code or Hexa decimal code".
    EX:    S   =   new student( );

                C  =  new circle( ); 
           
               R =  new   rectangle( );

    No comments:

    Post a Comment

    Thanks for visiting my site..