Java OCA OCP Practice Question 2744

Question

Given the following code, which of the following statements are true?

public class Main {
   public Main(int i, float f) { }
   public Main(float f, int i) { }
   public Main(float f) { }
   public void Main() { }
}
  • a. A syntax error will occur because void cannot be used with a constructor.
  • b. A syntax error will occur because the first two constructors are not unique.
  • c. The class does not have a default constructor.
  • d. No syntax errors will be generated.


c and d

Note

The last line is a method that happens to have the same name as the constructor.

As there are constructors defined but no default constructor, the class has no default constructor.




PreviousNext

Related