Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static abstract final for contructor

 
sura watthana
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic