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. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

5th Sep 2016, 2:07 PM
Bhavana
6 Answers
+ 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!.
5th Sep 2016, 2:25 PM
Ousmane Diaw
+ 2
class has constructor. whicb has arguments, which are animals features
7th Sep 2016, 7:32 AM
Sarpreet Khehra
Sarpreet Khehra - avatar
0
because compiler invoke a defalut constructer if we do not give a explicit constructer.
6th Sep 2016, 12:47 PM
Azeem Ahmad
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.
13th Sep 2016, 2:29 AM
Sanjeev Pratap Singh
Sanjeev Pratap Singh - avatar
0
All classes have a method called constructor that initializes. To which you can add arguments that are the characteristics of the object
16th Sep 2016, 1:45 PM
Julio César López Rodríguez
Julio César López Rodríguez - avatar
- 5
First of all dog is not object, it is reference variable in which reference id of the object is stored.
7th Sep 2016, 12:43 PM
Shubbh Arora
Shubbh Arora - avatar