learn java
The moose likes Beginning Java and the fly likes Query  -> inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Query  -> inheritance" Watch "Query  -> inheritance" New topic

Query -> inheritance

Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47

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?

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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!

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
It is sorta covered in the JavaRanch Style Guide.
subject: Query -> inheritance