0

object and classes

can anyone explain what is this code says Animal dog = new Animal();

14th Jul 2017, 3:05 AM
Bishal waiba
Bishal waiba - avatar
1 ответ
+ 2
This instantiates a new object of the Animal class and gives it the variable name dog. If dog was the house, the Animal class would be the blueprint for the house. We can use the blueprint (class) to build several houses. Even though the blueprint was the same for each house, each house is different and may have different traits or properties. One house may be painted blue with white trim and have hardwood floors, while the next may be painted yellow and have tile and carpeted flooring. The variable name dog refers to that specific Animal only. Just like each house would have it's own unique address. The variable name dog can be used to access the objects methods (actions) such as move() and properties (traits) such as setting the dogs species .
14th Jul 2017, 4:02 AM
ChaoticDawg
ChaoticDawg - avatar