This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes constructor related Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "constructor related" Watch "constructor related" New topic

constructor related

Tausif Khanooni
Ranch Hand

Joined: Nov 14, 2002
Posts: 107
I found a statement in Dan's mock exam:
f. The implicitly declared constructor has package access.
the answer is "false"
can any one help me in understanding it?
regards and thanks

"Walking on water and building IT Architecture from <br />specification are easy if and only if both are frozen"
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
to every class that does not declare a constructor, one with no arguments will be provided!!
public class A{
you are free to create instances of A using new A(), which is an implicit declared constructor. But with class B:
public class B{
public B(int x){}
you can only create instances of B using the only the following statement: B b=new B(i); for example. There is no empty constructor. So u cannot create a b instance with "new B()".
This implicit constructor has the same access of
the owner class.
public class A{}
is the same as
public class A{
public A(){}
class B{}
is the same as
class B{

notice that the access of class B is the same of the implicit constructor. In this case, package level access!
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
The following is the full text of the question.

Which of the following statements are true?
a. class A extends Object.
b. Field i1 is implicitly public because class A is public.
c. Method m1 is implicitly public because class A is public.
d. The compiler will insert a default constructor implicitly.
e. The implicit constructor declaration has no throws clause.
f. The implicitly declared constructor has package access.
g. The implicitly declared constructor accepts one parameter for each field in class A.
h. The implicitly declared constructor invokes the no-parameter constructor of the superclass.
i. None of the Above
As Leandro has stated, the implicitly declared constructor has the same access level as the class. In this case, the access level of the class is public so the access level of the implicitly declared constructor is also public. Therefore, answer option f is false.
The above is a demonstration of why an answer option quoted out of context can be misleading. When asking for an explanation of an answer it is always a good idea to also quote the question.

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="" target="_blank" rel="nofollow">Try my mock exam.</a>
Tausif Khanooni
Ranch Hand

Joined: Nov 14, 2002
Posts: 107
Thank you both.
sorry dan, i will remember your point hereafter.
Have you checked out Aspose?
subject: constructor related
jQuery in Action, 3rd edition