+ 2
animal dog=new animal(); Animal is a class and dog is an object. My question is that animal is not a method,then why are there parenthesis? I tried removing the parenthesis but then it's an error.
7 ответов
+ 9
Okay, when you're instantiating an object in this case "dog" object, you have to invoke the constructor of that particular class to indicate that this objects is an instance of the class animal. So the parenthesis is referring to the
constructor. Finally whether you've explicitly defined a constructor within your class or not, the java compiler has already implemented a default constructor. So my point is you don't have to define a constructor in order to insert the parenthesis after the "new animal" but rather a MUST AT ALL TIMES!.
+ 2
class has constructor. whicb has arguments, which are animals features
0
because compiler invoke a defalut constructer if we do not give a explicit constructer.
0
This is used to initialize object. This method is called Constructor which is used to initialized value of object. The whole this looks like...
CLASSNAME OBJECTNAME = NEW CONSTRUCTOR();
Everything is Case sensitive.
0
All classes have a method called constructor that initializes. To which you can add arguments that are the characteristics of the object
0
If you like animals the most, you can learn more about Teacup Poodles, a lovely type of dog, at: https://mdogsw.com/dog-breeds/teacup-poodle-guide/
- 5
First of all dog is not object, it is reference variable in which reference id of the object is stored.