Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Dan's q1 on constructor from single topic  RSS feed

 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following modifiers can be applied to a constructor?
a. abstract
b. final
c. private
d. protected
e. public
f. static
g. synchronized
h. transient
i. volatile
j. native
k. strictfp
l. None of the above.
The answer exclude synchronized. However following code compiles and works. As question is saying which modifiers CAN be applied, it should be part of answer list.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Barkat Mardhani:


Not so fast there, partner! That isn't even a constructor you've declared there! Once you provide a return type, you no longer have a constructor for class B, you have a method within class B named B.
If you were to remove the return type, you'd have a constructor and the compiler will give you an error.
Just to back that up, let's refer to the JLS, §8.8.3 Constructor Modifiers:


Unlike methods, a constructor cannot be abstract, static, final, native, strictfp, or synchronized.

 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Corey. That was quick reply
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!