rocket mass heater kickstarter
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes protected and default constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "protected and default constructor" Watch "protected and default constructor" New topic

protected and default constructor

Rashmi Tambe
Ranch Hand

Joined: Aug 07, 2001
Posts: 418
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... c1() has private access in pack.c1
^ c1(int) is not public in pack.c1; cannot be accessed from outside pa
2 errors
so i am confused :confused
could somebody explain this or i am interpreting the statement in some wrong way???
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
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.
jQuery in Action, 2nd edition
subject: protected and default constructor