• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Questions on for Kathy Sierr or Bert Bates

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am preparing for the SCJP exam. I am reading the bookd by Dathy S. and Bert B. I have a question about the answer for chapter 2 selftest 5.
FYI, here is the question:
How many of the following are legal method declarations?
1 - protedcted abstract void m1();
2 - static final void m1(){}
3 - transient private native void m1(){}
4 - synchronized public final void m1() {}
5 - private native void m1();
6 - static final synchronized protected void m1() {}
The answer said only 3 is illegal. I do hava a question about 1: If a method is abstract, the class that has it has to be abstract. If the class is abstract, then the method it contains has to be public. So I think statement 1 is illegal also.
Am I right? Or am I missing something?
Thanks
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


If the class is abstract, then the method it contains has to be public.


This is not correct. In an abstract class you can have private, protected, default, or public methods. Although, you can not have a private abstract method, because an abstract method has to be overridden, and a private method is not inherited.
However, in interface, all methods must be and are implicitly public and abstract, so it is illegal to declare an abstract protected method in interface. May be you were thinking of interface instead of abstract class?
Hope this helps.
 
ruby ruby
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response. You are absolute right.
 
You've gotta fight it! Don't give in! Read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic