Multiple choice technology programming languages

Which two allow the class Thing to be instantiated using new Thing()?

  1. public class Thing {}

  2. public class Thing { public Thing(void) { } }

  3. public class Thing { public Thing() { } }

  4. public class Thing { public Thing(String s) { } }

Reveal answer Fill a bubble to check yourself
A,C Correct answer
Explanation

To instantiate with new Thing(), the class must have a no-argument constructor. Option A has no explicit constructor, so compiler generates a default no-arg constructor - works. Option C explicitly defines a no-arg constructor - works. Option B is invalid syntax (void is not a valid parameter type). Option D only has a parameterized constructor, so new Thing() won't work.