• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Constructors

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had put this query a l'le while back but cudnt trace it
here it is again
just came across the following in suns java language specification
I aint agreeing onto the explanation given . Please F1 !!
class Point {
int x, y;
private Point() { reset(); }
Point(int x, int y) { this.x = x; this.y = y; }
private void reset() { this.x = 0; this.y = 0; }
}
class ColoredPoint extends Point {
int color;
void clear() { reset(); }// error
}
class Test {
public static void main(String[] args) {
ColoredPoint c = new ColoredPoint(0, 0);// error
c.reset();// error
}
}

EXPLANATION :
Another error occurs because ColoredPoint declares no constructors, and therefore a default constructor for it is automatically created (�8.8.7), and this default constructor is equivalent to:
ColoredPoint() { super(); }
which invokes the constructor, with no arguments, for the direct superclass of the class ColoredPoint. The error is that the constructor for Point that takes no arguments is private, and therefore is not accessible outside the class Point, even through a superclass constructor invocation (�8.8.5).

what I know abt constructors is that if any class (the current one (Coloredpoint in this case) or its ancestor (Point) have an userdefined constructor then the default constructor doesnt come into picture !!!
then why is it mentioned in the explanation that
a default constructor for it is automatically created (�8.8.7), and this default constructor is equivalent to:
ColoredPoint() { super(); }
please clear this doubt
thanks in advance
arawin99
 
Enthuware Software Support
Posts: 4820
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The rule is:
If any class (Coloredpoint in this case) has a user defined constructor then the default constructor doesnt come into picture.
Where did you get "or its ancestor (Point)" from??
-Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus
 
arawin99
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi paul ,
Try compiling the code given . In the explanation its mentioned abt runtime.
reply back
aarwin
 
Paul Anilprem
Enthuware Software Support
Posts: 4820
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Default constructor is created for ColoredPoint and not for point because ColoredPoint does not have any userdefined constructor. There is nothing more in it than that. Your basic premise is wrong and so your inference is wrong.
-Paul.

------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'arawin99'
PROPER NAMES ARE NOW REQUIRED!! and your name doesnot comply with the official naming policy.
Read this post for more details.
Ajith
reply
    Bookmark Topic Watch Topic
  • New Topic