0

I have created a HashSet and a HashMap and I am currently unsure as to whether I need to now declare a constructor.

Can Java run without a constructor ?

private HashSet <String> allJewelCards = new HashSet <String>();
private HashMap <String, Diamond> allDiamonds = new HashMap <String, Diamond>();
Bantu Tech
  • 234
  • 4
  • 15
  • 3
    Constructor for what? I think you're misunderstanding basic concepts here. – Maroun Nov 27 '14 at 15:17
  • In addition to @MarounMaroun, the entry point in every java based application is the `public static void main(String[] arguments)` method (not considering web apps). – Morfic Nov 27 '14 at 15:19
  • possible duplicate of [Can a class have no constructor?](http://stackoverflow.com/questions/13773710/can-a-class-have-no-constructor) – Florent Bayle Nov 27 '14 at 15:30

1 Answers1

4

If you don't explicitly declare a constructor it's the same as doing

public class SomeExample {

    public SomeExample() {}

}

As for your two fields allJewelCards and allDiamonds, they're initialized so you don't have an inherent need to declare them in a constructor.

Maroun
  • 94,125
  • 30
  • 188
  • 241
Rogue
  • 11,105
  • 5
  • 45
  • 71