*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes another question on constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "another question on constructors" Watch "another question on constructors" New topic
Author

another question on constructors

Rajani Sudhakar
Ranch Hand

Joined: Apr 28, 2004
Posts: 60
Question: You can only call public and protected constructors of the
super class in a subclass if the subclass is not in the
same package because only those are inherited.




Correct Answer : false


Can anyone explain me why the above statement is false...

Thanks in advance..

regards..
rajani.,

(changed title so that people know which is which)
[ May 14, 2004: Message edited by: Barry Gaunt ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729

Question: You can only call public and protected constructors of the
super class in a subclass if the subclass is not in the
same package because only those are inherited.


For the above to be true, there must be another condition on the superclass: it must be public to be visible to the subclass. So IMHO, in the general case, the above answer of "false" is correct.
[ May 15, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ana Abrantes
Ranch Hand

Joined: Sep 04, 2003
Posts: 43
Constructors are not inherited.


Ana<p>SCJP 1.4
Rajani Sudhakar
Ranch Hand

Joined: Apr 28, 2004
Posts: 60
I got the point....
Constructors are not inherited..

Thanks for ur reply..

regards..
rajani.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You have forgotten constructors wirh default (package) access.
[ May 15, 2004: Message edited by: Barry Gaunt ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: another question on constructors
 
Similar Threads
Rules Roundup Q309
JQ+: Constructors and access
Access control
access modifier and constructors
help me