Sun Certified Programmer for the Java 2 Platform
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Originally posted by Srinivasa Raghavan:
... Java compilerinserts a default constructor when there is no constrcutor in the java code it has the following signature public constructor(){} ...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by Kevin Peterson:
Yes I agree but isn't the default constructor that they give you just a method that takes no args and has no implementaion so giving the example of public constructor () {} would be simular to the default constuctor...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
James Carman, President<br />Carman Consulting, Inc.
Originally posted by James Carman:
Yes, Marc, that's what we call the "default" constructor. It's not necessarily the one provided by the compiler, but the no-argument one which is automatically called by subclasses (and Class.newInstance()) if they don't call another one specifically.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
-Venu Navat
James Carman, President<br />Carman Consulting, Inc.
Originally posted by Anupam Sinha:
Can you think of any scenario when a call to super() would not be automatically inserted. (other than when you already have inserted super()).
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
... As far as I know, that's *not* the terminology Sun promotes - they use the term "default constructor" *only* for the one implicitely generated by the compiler. See http://java.sun.com/developer/TechTips/1998/tt0811.html#tip2 for a good example.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Well, the part of the JLS you quoted above defines the term "default constructor"...![]()
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
-Venu Navat
Originally posted by venu navat:
code
____________________________________________________________________________
class ParentClass
{
public ParentClass(String a) // no no-arg constructor
{}
}
public class test22 extends ParentClass
{
String str;
public test22(String a)
{ this.str = a; }
public static void main(String args[])
{
test22 t = new test22("String");
}
}
___________________________________________________________________________
suppose if the parentclass is an interface,then call to super() would not be automatically inserted.....
is it correct scenario, anupam sinha???
James Carman, President<br />Carman Consulting, Inc.
Originally posted by venu navat:
code
public class ParentClass
{ ... }
public class test22 extends ParentClass
{ .... }
suppose if the parentclass is an interface,then call to super() would not be automatically inserted.....
is it correct scenario, anupam sinha???
-Venu Navat
Originally posted by Steven Bell:
I wish people would actually try to compile or run some of the code before they post it.
This does not compile. There is an error informing you that you must place and explicit call to super(String) in the test22 constructor because the super class has no default/no-args constructor.
Originally posted by venu navat:
Ali pope.....i mentioned ....IF parentclass is assumed as an interface and if test22 implements it ,then call to super class constructor would not be automatically inserted......bcoz interface donot have constuctors......
i request anupam sinha to respond to this answer......
James Carman, President<br />Carman Consulting, Inc.
Originally posted by Anupam Sinha:
Hi Steven
So what do you think I posted this code for?
-Venu Navat
Originally posted by venu navat:
... yes..i got you...if subclass don't extend from superclass,then super()will not be inserted automatically...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by venu navat:
hi anupam,
yes..i got you...if subclass don't extend from superclass,then super()will not be inserted automatically...
Originally posted by Steven Bell:
There is no such thing in Java, that you can write, that is a class without a superclass. All classes have a superclass, all constructors have a call to super in them.
Originally posted by Anupam Sinha:
No not all constructors have a call to super(). Please refer to posts above.
James Carman, President<br />Carman Consulting, Inc.
Originally posted by Steven Bell:
Even with this() the superclass constructor is still called, the compiler is simply smart enough not to call it twice. Notice that a call to this() must be the first statement in a constructor because it is the call to super().
James Carman, President<br />Carman Consulting, Inc.