• 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
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Exam Lab Question regarding ovverriding

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all,

I have faced the question in exam lab,the code is




In the above code,the getValue() in Tsuper(super class) has the default access specifier,In the TSub(Sub class) getValue has the protected access specifier,

According to the overrriding rules,

The overriding method is less restrictive than overriden method.But here the getvalue not statisfy the above condition.

Then how the above code compiles fine?.I can't understand.

Please explain the context.
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muneeswaran wrote:In the above code,the getValue() in Tsuper(super class) has the default access specifier,In the TSub(Sub class) getValue has the protected access specifier,

According to the overrriding rules,

The overriding method is less restrictive than overriden method.But here the getvalue not statisfy the above condition.

Then how the above code compiles fine?.I can't understand



Hello Munees, the access modifiers goes like this 'from less restrictive to most restrictive';

public-protected-default-private

Use it to check the program again and you will understand why it compiles.

Regards

Ikpefua
 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ikpefua.

Thanks for your reply.You just broke down my wrong myth.Thanks again.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic