0

Can anyone tell what does this statement do-"Animal dog = new Animal()"?

8th Jun 2018, 8:38 AM
Aarnav Saxena
Aarnav Saxena - avatar
4 Answers
+ 10
"Animal" is the name of the class that your going to create an object from "Dog" is a variable that is going to hold the refrence name to your new object, you use dog to access you objects methods like dog.bark(); //output woof woof 😀 "=" assigns the refrence to your variable to access your new 🐕 object "new" creates the object (creates some space in heap memory) and "Animal()" is the constructor you can use the constructor to initialize your class variables.
8th Jun 2018, 9:24 AM
D_Stark
D_Stark - avatar
+ 1
Animal -> class dog -> object new -> assigns memory for dog
8th Jun 2018, 8:46 AM
‎ ‏‏‎Anonymous Guy
0
Animal is the class, dog is the object and the new creates the object. the class name after that is the constructor and it is mandatory to put. you can also access the Animal class methods for example: dog.bark(), dog.walk(1).
13th Jun 2018, 5:55 AM
DengSXCreates
DengSXCreates - avatar