• 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

Inheritance

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

give me your advises (on the way to scjp exam)

as you can see the code.

1. In case both the files are in the same package than there is no problem in inheritance unless the methods of Car class are private.
2. but when the classes are in the separated directories as below than i can only use two access specifiers for methods of class Car so that they get inherited in class test5, that two are, public and protected.
if i don't specify a access-level than it will be by default package, which means no matter inherited from where as long as its outside that package it cannot be accessed.

i used to mark those two methods(fast,slow) as package(i didn't specify the access specifiers) than i couldn't access them in test5.

i'm little bit confused, though i understand how it works, but i need some advises and recommendations from those who have experience in such tricky topics.






thanks guys,
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I couldn't understand your question.
 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Neha Daga wrote:I couldn't understand your question.


so simple ... my superclass Car is in food package, my subclass test5 is in main directory(base directory, different from food) now if i mark methods of Car as default:


than i will not be able to access these methods in my subclass, but when i mark them as protected or public than i can access them, i was just confused why can't i access a member with default access specifier.

but i understand the topic now
 
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic