jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes static abstract final for contructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static abstract final for contructor" Watch "static abstract final for contructor" New topic
Author

static abstract final for contructor

sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
Hi ,

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 ]
Mamatha Preetham
Ranch Hand

Joined: Jan 23, 2007
Posts: 75
Hi Sura,

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.

mamatha.
SCJP(1.4)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14107
    
  16

Hi Sura,

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.

Here are some pointers:

Understanding Instance and Class Members (about static)
Writing Final Classes and Methods (about final)
Abstract Methods and Classes (about abstract)


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static abstract final for contructor