This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access control

 
sweety sinha
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
source is: http://www.jdiscuss.com
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.

my answer is true
but the answer given is false why?
 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, i guess even the default constructors can be called.

Your answer is right if Constructors is replaced by "Methods"

Correct me if i am wrong.
 
sweety sinha
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think i have done a mistake, because constructor is never inherited
 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, constructor is never inherited.

The correct statement would be

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 accessible.

Also remember that if you don't provide explicit constructor for a class, the default constructor provided by the compiler has the same accessibility as the class.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic