Question about constructors in Java

I have a few questions regarding Java constructors

  • Can a constructor be closed? If so, in what condition?
  • Is the method constructor or not?
  • If the constructor returns nothing, then why do we call a new object each time?
  • What is the default access modifier of the constructor, if we do not specify.

Edit

The answers for 1 and 3 are very clear. I am still not sure about 2 and 4, since I have different answers for them.

+3
source share
8 answers
+2

? , ?

. . , , , .

: static getInstance() .

, .

- ?

. ". , " ". ? , , .

, .

new - ( ).

.

, . -.

- , , , , .

+3
  • , . , , , factory , , Singleton.
  • , . , .
  • , .
  • . , .

Tomcat:. , , , , .

500. , , , 1 , .5 , . , . , , , JBoss.

+1
  • .
  • - , , , .
  • - , .
0
  • - factory , factory.
  • ,
  • , - . ( , )

Tomcat, , Tomcat, - (, NIO -) . Tomcat , concurrency ( ).

0

CLASS ACCESS MODIFIER, , . , .

0
  • .
  • - , , .
  • . . .
0
  • .
  • .
  • because the constructor is being called new. What the object returns new, the constructor simply sets the internal state.
  • Public
-1
source

Source: https://habr.com/ru/post/1785121/


All Articles