Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inherited library

 
Christophical Lee
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic