• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructors  RSS feed

 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we dont specify a constructor for a class, we know that a default constructor will be generated for the class. Is it true tht the generated constructor will have the access specifier as public if the class is public or else no access specifier?
 
Jasmine kaur
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
well when class is public or not the default constructor is created when no other constructor has been called ,well I want to tell you that constructors are never inherited .We can make cosntructors private also,But if you are not satisfy by the anwser then you can ask further questions for more clarifiaction.
Thanks
Jasmine
 
himanshu patel
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vineela Devi Jakka:
If we dont specify a constructor for a class, we know that a default constructor will be generated for the class. Is it true tht the generated constructor will have the access specifier as public if the class is public or else no access specifier?

The compiler gives default constructors the same access level as their class. For example, if class is public, so the default constructor is public. If class is given package access, the default constructor would be given package access.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!