how to create object 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: how to create object js

function person(fname, lname, age, eyecolor){
  this.firstname = fname;
  this.lastname = lname;
  this.age = age;
  this.eyecolor = eyecolor;
}

myFather = new person("John", "Doe", 50, "blue");
document.write(myFather.firstname + " is " + myFather.age + " years old.");

Example 4: how to create a object in javascript

var a = {
name: "aakash",
  age:30
}

Example 5: how to create an object in javascript

const person = {
  name: 'Anthony',
  age: 32,
  city: 'Los Angeles',
  occupation: 'Software Developer',
  skills: ['React','JavaScript','HTML','CSS']
};

//Use Template Literal to also log a message to the console
const message = `Hi, I'm ${person.name}. I live in ${person.city}.`;
console.log(message);

Example 6: how to create a object in javascript

var about = {
  name:"lanitoman",
  age:1023,
  isHeProgrammer:true
}