• Post Reply Bookmark Topic Watch Topic
  • New Topic

Default Constructor Prototype  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the default constructor prototype for a public class?!?! say:

my guess is public Test() but the mock exam I am taking just says Test()!!
Thanks
 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Test() is the basic prototype.
public class means it is open to everyone but
this does not necessary means everyone can freely create
instance of that class.
my 2cs
 
Andree Charfen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you sure about this??? I think if the class is public the default prototype constructor is also public!
Anybody else?
maybe a second opinion would ok!
 
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Section 8.8.7 of the JLS says that a public class gets a public default constructor.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so if your class Test is public the default constructor as created when you omit one from the class definition would be "public Test(){super();}" and not "Test(){super();}".
 
Andree Charfen
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok! So.. I guess that mock test is wrong. Man.. there are so many misleading tests out there!! arrrrgg!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!