For create a new instance of contract you must to use the word 'new' and the name of the contract like:
[NameContract] contract = new [NameContract]();
With this statement you could use it to create a new child contract in a function
or in parent contract's constructor
.
See this example:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
contract ParentContract {
// State variable ParentContract
ChildContract private child;
constructor() {
// Create a new Child contract
child = new ChildContract("Test", 30);
}
}
contract ChildContract {
// State variables Child contract
string name;
uint age;
constructor(string memory _name, uint _age) {
name = _name;
age = _age;
}
}
If you want more details, see here.