This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes inherited library Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inherited library" Watch "inherited library" New topic

inherited library

Christophical Lee

Joined: Sep 02, 2010
Posts: 1

if i have class Parent that has import lib.bird;

and i have Child that extends Parent but I want to use pro.bird instead, is that possible?

Can i override the library?
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

Is both your Child class & Parent class in the same file? In that case, use 'pro.bird'(fully qualified name) in your child class to refer 'bird' and this will override the whatever imports you have made for 'bird'.
For example, you might have imported Date from util package

but at a certain part of your program, you might want to use Date class that is inside sql package

would solve the ambiguity problem.

and Christophical Lee, Welcome to Ranch!

Rob Spoor

Joined: Oct 27, 2005
Posts: 19697

Imports are only relevant for source files, not classes themselves. They are little more than a tool that allows programmers to be lazy. Without them you had to write java.util.List, javax.swing.JPanel etc all the time. So yes, if your two classes are located in different files, then you can import lib.bird in one file and pro.bird in the other.

How To Ask Questions How To Answer Questions
GeeCON Prague 2014
subject: inherited library