• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Why cannot constructors be final

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

why can't constructors be final as we can not inherite constructors.

Loka
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think it is anything to do with inheritance. I think it is just that if you have your constructor final, there is no point in creating a new object, because you would not be able to modify any fields/methods of that class. I might be wrong too...

Thanks,

-Vijay
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Itz somehow related to inheritance.First of all u think when'll u use final modifier in class / method / variables(instance / local).

class - when class should not be subclassed

Method - when method should not be overridden

variable - when its value should not be modified

Now coming to constructors we can say it is a spl kinda method in a class.

No way constructors(of any class) are gonna be inherited by its subclass irrespective of its access modifier.So u cant override something which cant be inherited.So y do u wanna use final modifier with constructors?.

Something which doesn't give meaning cant / shouldn't be used..rite?!!

That must be the reason Sun wud have prevented using final modifier with constructors.

Hope u got my point!!!

Regards,
Priya.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. A subclass does inherit its base class' constructors. Otherwise, the subclass could not invoke the base class' constructor from its own constructors.

2. A constructor is not a method, so it cannot be overridden. So there is no need for a final qualifier.

(I have not read the previous post because it is not written in english)
 
Vijay Gade
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Barry,

You were saying something about the previous post not being written in English. Was that my post? Pardon my ignorance but I am just curious. Maybe it is not at all related to my post

Thanks,

-Vijay
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1. A subclass does inherit its base class' constructors. Otherwise, the subclass could not invoke the base class' constructor from its own constructors.

I respectfully disagree. The subclass calls the superclass' constructor, not an "inherited" one. Only class members are inherited, and the JLS specifically excludes constructors from this classification (� 8.8: Constructor declarations are not members. They are never inherited and therefore are not subject to hiding or overriding.).

(I have not read the previous post because it is not written in english)


Agreed.

Please make the extra effort to write out words such as "why", "you", "would", etc. The extra keystrokes won't cost much in the way of time, and the enhanced clarity will be appreciated by those communicating on a forum with international readership.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vijay Gade:

You were saying something about the previous post not being written in English. Was that my post?



I think he's talking about Priya Jothi's "spl" post.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't it simple like this:

Overridding does not make sense in case of constructors, since class name and constructior name should be same. You are asking a question which has a scenario as below.

Isn't it?
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was just writing some stuff about constructors and created a class that demonstrated something I already knew (but yuou ahve to check). Constructors are not inherited. Thus I was correct and Barry was not. Barry was wrong, Barry was wrong, Barry was wrong...

(does this make me childish?)...

Oh, yes and I agree, please do not use contractions such as wanna,gonna etc, clarity is very important. Many people in these forums have English has a second language and such contractions can confuse. This is not about the ability to speak/write perfect English, we do not expect that at all, just give it your best shot to communicate as clearly as possible and not introduce any ambiguity. And Prya, you contributions are greatly appreciated, please don't take this as anyone "wagging their finger" at you
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vijay Gade:
Hello Barry,

You were saying something about the previous post not being written in English. Was that my post? Pardon my ignorance but I am just curious. Maybe it is not at all related to my post

Thanks,

-Vijay



No, it was not your post. Nor was it the original post. Not much choice left is there?


What I am reacting to is the (increasing) usage of "text speak". I just turn away from it now. Spell the words out as in an English dictionary.

This I would read:


Hi,

It's somehow related to inheritance. First of all you think when will (?) you use final modifier in class / method / variables (instance / local).

class - when class should not be subclassed

Method - when method should not be overridden

variable - when its value should not be modified

Now coming to constructors we can say it is a special kind of method in a class.

No way constructors(of any class) are going to be inherited by its subclass irrespective of its access modifier. So you can't override something which can't be inherited.So why do you want use final modifier with constructors?.

Something which doesn't give meaning can't / shouldn't be used..right?!!

That must be the reason Sun would have prevented using final modifier with constructors.

Hope you got my point!!!

Regards,
Priya.


[ July 30, 2005: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I am wrong according to JLS. My fuzzy way of thinking led me to state that the constructor had to be inherited for the subclass constructor to be able to use super() (explicitly or implicitly). I stand corrected. Thanks. However, in my second point I wrote that a constructor was not a method and excluded the possibility of overriding (and implicitly hiding) it.

Constructors are not inherited.
Constructors are not inherited.
Constructors are not inherited.
Constructors are not inherited.
Constructors are not inherited.
.
.
.
Constructors are not inherited.

When I get my paper version of JLS 3.0 I will read that section aloud twenty times while having my back lashed with a wet kipper (or is it mackerel).
 
Arulkumar Gopalan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Marcus:
please do not use contractions such as wanna,gonna etc, clarity is very important. Many people in these forums have English has a second language and such contractions can confuse.



I don't think the usage is because of English is a second language. These words are frequently used by the people who have English as the first language. so, others do follow that.


Barry:
What I am reacting to is the (increasing) usage of "text speak". I just turn away from it now. Spell the words out as in an English dictionary.



I understand/agree that it is recommended to use proper English in technical forums. But, I don't think Priya's communication was bad in such a way none could understand.

Perhaps you could have communicated directly to use proper text English instead of saying "it is not written in English".
(As Steve did.)
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lokanadham Nalla:
why can't constructors be final as we can not [override] constructors.



If you could declare a constructor final and did not, what would that imply?

Given the choice among requiring it, prohibiting it or leaving it as optional they chose to prohibit it. Constructors are special so having special requirements is not an issue.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Arulkumar Gopalan:


I understand/agree that it is recommended to use proper English in technical forums. But, I don't think Priya's communication was bad in such a way none could understand.

Perhaps you could have communicated directly to use proper text English instead of saying "it is not written in English".
(As Steve did.)



Thanks for posting your view.

I think that the point that Marcus was making, was that many readers have English as their second language. If "text-speak" makes it harder for a english reader, then what does it do for a reader with English as a second language? "Text-speak" unfortunately makes the poster seem somewhat illiterate even if he or she isn't. It's also a matter of respect for your audience. A reduction in line noise is for everyone's benefit.

I agree with and accept your point about communicating more directly, but I had intended that my comment should have such an impact.
Cheers
-Barry
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, are abbreviations like "IMHO", "AFAIK", "BTW", "ASAP"... etc acceptable here?
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joyce Lee:
So, are abbreviations like "IMHO", "AFAIK", "BTW", "ASAP"... etc acceptable here?



Personally, I am a french speaker.
I know
IMHO means In My Humble Opinion
BTW means By The Way
ASAP means As Soon As Possible

But I have no idea of the meaning of AFAIK.

And I think that ASAP is not appropriate in a forum. Everything is urgent for everyone. So require a response ASAP is the same, IMHO , than posting a question.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vincent,

But I have no idea of the meaning of AFAIK.
AFAIK is an acronym for As Far As I Know. Honestly speaking, I'd trouble understanding some of the acroynms initially and they're used quite commonly here without much complaints from others. So perhaps it's better to spell out the whole word for clarity.

And I think that ASAP is not appropriate in a forum. Everything is urgent for everyone.

Actually, I simply used ASAP as an example for abbreviation. The phrase as soon as possible can be used in many contexts.

Joyce
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joyce Lee:
So, are abbreviations like "IMHO", "AFAIK", "BTW", "ASAP"... etc acceptable here?



Good point Joyce! These are Usenet abbreviations. They have been around for many years now. Probably originally used when 600baud single duplex lines were in fashion. I found AFAIK was listed four times when using Dictionary.com from the Firefox search bar. They come from bulletin board/news culture and, in my humble opinion, are in a different league to "4 u", "thanx", "bcos" which come from chat (where you need to get information over in a few seconds) or mobile phone messaging (where you are limited to around 160 characters in a message).

So to your question I would answer: "Acceptable but discouraged".
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lokanadham Nalla:
Hi there,

why can't constructors be final as we can not inherite constructors.

Loka



Just consider constructor as a special method:
The only access modifer allowed is public,private and protected.

Any other modifers,i.e., void or any return tppe will just make the constructor 'ordinary'

or just illegal, like static, final,synchronized

Remember this rule is enough for the exam!
 
This tiny ad is wafer thin:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic