java object creation code example

Example 1: object instantiation vs construction

Object Creation (Instantiation) and Initialization (Construction) are 
different things in Java. Construction follows object creation.
Object Creation is the process to create the object in memory and 
returning its handler.
Java provides “new” keyword for object creation.
Initialization is the process of setting the initial/default values 
to the members.
Constructor is used for this purpose. If we don't provide any constructor, 
Java provides one default implementation to set the default values according 
to the member data types.

Example 2: java create new object

Car mycar = new Car();

Example 3: make an object in java

public class Puppy {
   public Puppy(String name) {
      // This constructor has one parameter, name.
      System.out.println("Passed Name is :" + name );
   }

   public static void main(String []args) {
      // Following statement would create an object myPuppy
      Puppy myPuppy = new Puppy( "tommy" );
   }
}

Example 4: create object and call method in java

MyClass **insert_name** = new MyClass();
        insert_name.**method_name**();