0
class Cat{
    String name;
    int age;

    Cat(){
        String name = "Tom";
        int age = 3; 
    }
}

I have a confusion about if Cat() is a default constructor or a no argument constructor(non default constructor).I just want to that here Cat() is a default constructor or a no argument constructor(non default constructor)?

luk2302
  • 55,258
  • 23
  • 97
  • 137
  • 2
    Since you have written it it cannot be the default constructor. – luk2302 Jan 14 '23 at 08:09
  • 1
    I understand you confusion. I pretty often see a no-arg constructor referred to as *default constructor*, which it isn’t if it’s a declared constructor. The opposite is true, though: a default construcotr is generated automatically by the compiler and never takes argument, that is, it is a no-arg constructor. – Ole V.V. Jan 14 '23 at 08:31
  • Perhaps also related: [What is the purpose of a no-arg constructor?](https://stackoverflow.com/questions/48553000/what-is-the-purpose-of-a-no-arg-constructor) – Ole V.V. Jan 14 '23 at 08:36

0 Answers0