• 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

protected and default constructor

 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JQ+Question ID :958265097150
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. True/False?
ANS: false
Explaination is really strange. But i dont understand why the statement is false. i tried following code. class c2 inherits from c1 which is in different package and it has one protected and one default constructor. While creating object of class c2 , compiler gives error...

The error is as follows...
c2.java:2: c1() has private access in pack.c1
{
^
c2.java:3: c1(int) is not public in pack.c1; cannot be accessed from outside pa
ckage
super(i);
^
2 errors
so i am confused :confused
could somebody explain this or i am interpreting the statement in some wrong way???
TIA
Rashmi
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Rashmi,
the statement is partially true but the reason being argued for that is false and so the answer is false.
it says "because only those are INHERITED..." now, constructors are never inherited. it's accesss is just determined by the access modifier when we call super() and depending upon that the access will be rejected or accepted.
regards
maulin.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic