📜  什么是实例化 OOP? - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:36.353000             🧑  作者: Mango

代码示例1
It is the creation of a new instance of an object, with respect to OOP.

Suppose we have a programming class called “Dog”. To instantiate this class we create a new object of type Dog. We would do something like this:

// this is instantiation 
Dog myDog = new Dog(); 
// set properties of the dog 
myDog.setName(“Fido”); 
myDog.setAge(3); 
myDog.setBreed(“Airedale”); 
// other instantiation methods, if the constructor is overloaded 
Dog bigDog = new Dog(“Rover”, 4, “Great Dane”);