I came across a contructor topic in my book it says
contructors can't be marked static.
contructors can't be marked final.
contructors can't be marked abstract.
it doesn't really say why?
could anyone give me a good reason for the statements above. Thank you
Sura [ February 06, 2007: Message edited by: sura watthana ]
Joined: Jan 23, 2007
The purpose of constructors is to create an instance of a class, they are used to initialize the instance variables(fields) of that class.
Constructors are similar to methods, but with no return type.. Like methods, constructors can have any of the access modifiers: public, private, protected, default...But, they cannot be marked final, abstract and static...
Constructors are not inherited, in other words, they cannot be overriden, so there is not need to declare it final...At the same time, constructors can be overloaded...
An abstract constructor can never be implemented, so it cannot be marked abstract....
A constructor is invoked to instantiate an object of a particular class, so it will be meaningless for a constructor to be static...A method is marked static so that it can access other static members... These rules can be found in Java Language Specifications(JLS) Even I had similar doubts in my initial days of java learning.
Do you know exactly what "static", "final" and "abstract" mean? Read up on those concepts and think about what they would mean with regard to constructors, then you'll discover why those concepts do not apply or don't make sense for constructors.