• 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

constructor related

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to every class that does not declare a constructor, one with no arguments will be provided!!
example:
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(){}
}
BUT
class B{}
is the same as
class B{
B(){}
}

notice that the access of class B is the same of the implicit constructor. In this case, package level access!
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both.
sorry dan, i will remember your point hereafter.
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic