how to create objects in java code example

Example 1: java create new object

Car mycar = new Car();

Example 2: 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 3: create object and call method in java

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

Tags:

Java Example