Skip to content
Advertisement

Tag: constructor

How many times is a constructor called when it’s overloaded?

BankAccount.java Test.java I should get number of accounts is 3 but I’m getting 4. If I instantiate all accounts with the parametrized constuctor, I get 3. If I add BankAccount account4 = new BankAccount();, I get 6. Is the default constructor called twice? Answer This is your problem: The explicit call to the other constructor BankAccount(double, double) increments numberOfAccounts. Then

Java, my own copy() method would not work

I am learning java and came upon a small problem, my copy() method will not work. I work based on a UML diagram and I am pretty sure that I’m doing everything correctly. Here is the code: Constructor: copy() method: The error flashes at the parantheses FileName() it says: ‘FileName(java.lang.String, java.lang.String)’ in ‘Exam_Practice_4.FileName’ cannot be applied to ‘()’ Here is

Since when have enum constructors’ default access modifier been private?

How long have enum constructors’ default access modifier been “private”? Since the beginning or did it change in Java 8? If it did, then what was the default access modifier of a constructor declaration with no access modifier? (I’m guessing it is the default(package accessible) like other java classes’ constructors.) I found some reference documents related to this, but couldn’t

Advertisement