[ajug-members] Classes Interfaces Constructor
Joe Sam Shirah
jshirah at attglobal.net
Thu Jun 10 12:25:13 EDT 2004
Hi Berlin,
> I am trying to figure how constructors are implicitly called, for example.
See the Java Language Specification at
"8.8.5 Constructor Body"
<http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#784
35>
and
8.8.7 Default Constructor
<http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#168
23>
>And are there ways to force an implementation of a
> constructor(adding 'abstract')
Not sure what you mean by the statement above.
> but what about
> public B() {
> // is super() implicitly added here? which calls blah()
> }
From the spec above, the answer is yes.
> or
> public B(String x) {
> // is super(x) implicitly added here also, which calls
another_blah();?
> }
Never happen. Only implicit calls to the default, no arg constructor
are added if no explicit super constructor is invoked.
There was a recent question about instance initializers at the Java
Filter Forum, and I found an article by Dick Baldwin that, while it does not
really talk about implicit, default constructors, is very helpful in
understanding the construction/initialization process. See
The Essence of OOP using Java, Instance Initializers
http://www.developer.com/java/other/article.php/3065621
Joe Sam
Joe Sam Shirah - http://www.conceptgo.com
conceptGO - Consulting/Development/Outsourcing
Java Filter Forum: http://www.ibm.com/developerworks/java/
Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
Going International? http://www.jguru.com/faq/I18N
Que Java400? http://www.jguru.com/faq/Java400
----- Original Message -----
From: "Berlin Brown" <bbrown at khafra.com>
To: <ajug-members at ajug.org>
Sent: Thursday, June 10, 2004 11:00 AM
Subject: [ajug-members] Classes Interfaces Constructor
I am reading the docs on Constructors and I am trying to figure how
constructors are implicitly called, for example.
And are there ways to force an implementation of a constructor(adding
'abstract')
public class A {
public A() {
blah();
}
public A(String val) {
another_blah();
}
}
public class B extends A {
public B() { super(); <-- of course this calls blah() above
}
but what about
public B() {
// is super() implicitly added here? which calls blah()
}
or
public B(String x) {
// is super(x) implicitly added here also, which calls
another_blah();?
}
}
Berlin Brown
bbrown at khafra.com
(404)979-6999
ext. 7260
More information about the ajug-members
mailing list