0

If I create a frame inside the 'main()', then only one instance of the frame would be created.

If I create a frame inside a constructor, then each time the class is instantiated, a new frame would be created.

Could someone give me some real-time scenarios where the above two methods would be used?

Sivani
  • 101
  • 1
  • It is not something that can be answered in one or two sentence, you need firstly learn the basics of Java language, then such kind of question can be answered by your self. Good Luck! – Bahramdun Adil Mar 07 '17 at 01:50
  • If this is not a duplicate, please edit your question to include a [mcve] that shows your chosen approach. – trashgod Mar 07 '17 at 01:52
  • 3
    The second generates a side effect which may not always be desirable, constructors should be focused on setting up the state of the object – MadProgrammer Mar 07 '17 at 01:59
  • 1
    @MadProgrammer ..another undesirable side effect of creating a frame in the constructor is that it locks the class into appearing in a frame! It might also be needed to display the component (a panel, presumably) in a window, a dialog, a tab of a tabbed pane, a split pane, one part of the layout of another panel .. The 'frame in constructor' presumably also sets the component visible at the same time, but that might not be the desired result. – Andrew Thompson Mar 07 '17 at 03:01
  • @trashgod Thanks for your guidance. Next time I'll frame my question properly. – Sivani Mar 07 '17 at 14:43
  • @MadProgrammer and Andrew Thompson: Thanks for your inputs, which answered my question partly. – Sivani Mar 07 '17 at 14:49

0 Answers0