• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Query -> inheritance

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

Suppose I inherit a public class in the same file and start using
the subclass, What would be the access specifier of the subclass???
Would it be a public class too? and can I inherit a public class in the same file?

Thanks
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can only put one top level class in a source file, so you can't really put a superclass and subclass in the same file. (Well, maybe you could, but not in the beginner forum .) This one-class-one-file rule makes life easier for the compiler and humans who go looking for source code.

I think you could extend a public class into a package level class. Give it a try and see.

Then try making a method public in the superclass and overriding it to be private in the subclass. See what happens and whether it makes sense.

Keep coding, keep asking, keep having fun!
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic