0
Can anyone tell what does this statement do-"Animal dog = new Animal()"?
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.
+ 1
Animal -> class
dog -> object
new -> assigns memory for dog
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).