Question about constructors in Java

前端 未结 8 645
我寻月下人不归
我寻月下人不归 2021-01-20 14:52

I have few questions regarding Java constructors

  1. Can a constructor be private? If yes then in which condition?
  2. Is a constructor a method or not?
8条回答
  •  星月不相逢
    2021-01-20 15:29

    1. Yes -- factory instance singletons often use this pattern, to force users to init their class via static factory method.
    2. Yes, it's a method
    3. Because that is what a constructor does - it constructs. (it's assumed the result of construction will be returned)
    4. same as methods

    With regards to your Tomcat question, it depends on which version of Tomcat, which IO model it's using (e.g., NIO versus historical network IO modules), and your configuration. Single Tomcat's can process hundreds of requests at a time, although the concurrency is tune-able (each request will be handled by a distinct thread or thread from a pool).

提交回复
热议问题