• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Access Modifier for Methods

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Access Modifier for Methods

Questions:
a) It is ok to say „static public void main(String args[]) ..“ (True/False)
b) It is ok to say „public void static main(String args[]) ..“ (True/False)
c) It is ok to say „void abstract method();“ (True/False)
d) It is ok to say „void method() {} instead of public void method() {}
When you implement abstract method (True/False)

Please answer and give a reason.
Thanks.
Thomas.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can answer the true/false questions yourself -- plop the code in a compiler, what happens when you substitute these lines in?
a) static public void main(String args[])
b) public void static main(String args[])
c) void abstract method()
d) void method() {} instead of public void method() {}
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Thomas Markl:
Questions:
a) It is ok to say „static public void main(String args[]) ..“ (True/False)
b) It is ok to say „public void static main(String args[]) ..“ (True/False)
c) It is ok to say „void abstract method();“ (True/False)
d) It is ok to say „void method() {} instead of public void method() {}
When you implement abstract method (True/False)

Please answer and give a reason.


For the example given above:
a. True
b. False. Modfiers + return value in that order, e.g. public static void main(String args[])
c. False. See b.
d. True. An overriding method can be at most as restrictive as the method being overriden.
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic