作者:
Tverous (Orah~)
2017-01-29 08:09:00在這詢問有關Math這個static method
有沒有曾經擁有過constructor
因為在搜尋之後發現它似乎是沒有的
但書上卻這樣寫
But you can restrict other code from instantiating
a non-abstract class by marking the constructor
private. Remember, a method marked private means
that only code from within the class can invoke
the method. A constructor marked private means
essentially the same thing-only code from within
the class can invoke the constructor. Nobody can
say 'new' from outside the class. That's how it works
with the Math class, for example. The constructor
is private, you cannot make a new instance of Math.
The compiler knows that your code doesn't have
access to that private constructor
大概是說Math不能被new是因為他的constructor被設為private
不知道我理解有沒有錯@@
看的是 HeadFirst Java
感謝