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

question about access modifier

 
Ranch Hand
Posts: 74
MySQL Database Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Options:

1.) # 1

2.) # 2

3.) # 3

4.) # 4

5.) # 5

6.) # 6

The compile-time erros is at #5, ma why?
In abstract class the access modifier are public and abstract, right?
Then, why the reason of the error is that public method cannot be restricted to a default method?

Thanks in advance for help
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please QuoteYourSources.

Henry
 
manu lix
Ranch Hand
Posts: 74
MySQL Database Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CertPal
 
Ranch Hand
Posts: 258
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you change your method name from toString to something else, it should works.
You are actually overriding toString method (and reducing the access level from public to default)
All classes implicitly extends Object which has toString method http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString()
 
manu lix
Ranch Hand
Posts: 74
MySQL Database Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raymond Tong wrote:If you change your method name from toString to something else, it should works.
You are actually overriding toString method (and reducing the access level from public to default)
All classes implicitly extends Object which has toString method http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString()



Ok, I agree!
But, in abstract class the methos are implicity public and astract, so:


toString() are public even if it has not been spelled out, ok?
 
Henry Wong
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

manu lix wrote:
But, in abstract class the methos are implicity public and astract, so:



Really? Can you provide a pointer for this statement?

Henry
 
manu lix
Ranch Hand
Posts: 74
MySQL Database Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

manu lix wrote:
But, in abstract class the methos are implicity public and astract, so:



Really? Can you provide a pointer for this statement?

Henry



Maybe, I am confused with interfaces
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

manu lix wrote:

Maybe, I am confused with interfaces



Only in interfaces, the methods are public and abstract by default.
 
reply
    Bookmark Topic Watch Topic
  • New Topic